Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,6 +6,7 @@ import pandas as pd
|
|
| 6 |
import torch
|
| 7 |
import matplotlib.pyplot as plt
|
| 8 |
import seaborn as sns
|
|
|
|
| 9 |
|
| 10 |
# Define constants
|
| 11 |
MODEL_NAME = "gpt2" # Publicly accessible model suitable for CPU
|
|
@@ -17,7 +18,7 @@ EXAMPLE_FILE = os.path.join(EXAMPLE_DIR, "titanic.csv")
|
|
| 17 |
os.makedirs(FIGURES_DIR, exist_ok=True)
|
| 18 |
os.makedirs(EXAMPLE_DIR, exist_ok=True)
|
| 19 |
|
| 20 |
-
# Download the Titanic dataset if it doesn't exist
|
| 21 |
if not os.path.isfile(EXAMPLE_FILE):
|
| 22 |
print("Downloading the Titanic dataset for examples...")
|
| 23 |
try:
|
|
@@ -184,20 +185,15 @@ def interact_with_agent(file_input, additional_notes):
|
|
| 184 |
# Append the summary
|
| 185 |
messages.append({"role": "assistant", "content": summary})
|
| 186 |
|
| 187 |
-
# Append images
|
| 188 |
for image_path in visualization_paths:
|
| 189 |
# Ensure the image path is valid before attempting to display
|
| 190 |
if os.path.isfile(image_path):
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
# For Spaces, images should be in the repository
|
| 197 |
-
messages.append({
|
| 198 |
-
"role": "assistant",
|
| 199 |
-
"content": f""
|
| 200 |
-
})
|
| 201 |
else:
|
| 202 |
messages.append({"role": "assistant", "content": f"⚠️ Unable to find image: {image_path}"})
|
| 203 |
|
|
@@ -246,6 +242,9 @@ Upload a `.csv` file, add any additional notes, and **the assistant will analyze
|
|
| 246 |
api_name="run_analysis"
|
| 247 |
)
|
| 248 |
|
|
|
|
| 249 |
if __name__ == "__main__":
|
| 250 |
demo.launch(share=True)
|
| 251 |
|
|
|
|
|
|
|
|
|
| 6 |
import torch
|
| 7 |
import matplotlib.pyplot as plt
|
| 8 |
import seaborn as sns
|
| 9 |
+
import base64
|
| 10 |
|
| 11 |
# Define constants
|
| 12 |
MODEL_NAME = "gpt2" # Publicly accessible model suitable for CPU
|
|
|
|
| 18 |
os.makedirs(FIGURES_DIR, exist_ok=True)
|
| 19 |
os.makedirs(EXAMPLE_DIR, exist_ok=True)
|
| 20 |
|
| 21 |
+
# Download the Titanic dataset if it doesn't exist
|
| 22 |
if not os.path.isfile(EXAMPLE_FILE):
|
| 23 |
print("Downloading the Titanic dataset for examples...")
|
| 24 |
try:
|
|
|
|
| 185 |
# Append the summary
|
| 186 |
messages.append({"role": "assistant", "content": summary})
|
| 187 |
|
| 188 |
+
# Append images by converting them to Base64
|
| 189 |
for image_path in visualization_paths:
|
| 190 |
# Ensure the image path is valid before attempting to display
|
| 191 |
if os.path.isfile(image_path):
|
| 192 |
+
with open(image_path, "rb") as img_file:
|
| 193 |
+
img_bytes = img_file.read()
|
| 194 |
+
encoded_img = base64.b64encode(img_bytes).decode()
|
| 195 |
+
img_md = f""
|
| 196 |
+
messages.append({"role": "assistant", "content": img_md})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 197 |
else:
|
| 198 |
messages.append({"role": "assistant", "content": f"⚠️ Unable to find image: {image_path}"})
|
| 199 |
|
|
|
|
| 242 |
api_name="run_analysis"
|
| 243 |
)
|
| 244 |
|
| 245 |
+
# Launch the Gradio app
|
| 246 |
if __name__ == "__main__":
|
| 247 |
demo.launch(share=True)
|
| 248 |
|
| 249 |
+
|
| 250 |
+
|