Update app.py
Browse files
app.py
CHANGED
|
@@ -55,6 +55,10 @@ agent = CodeAgent(
|
|
| 55 |
|
| 56 |
|
| 57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
def run_agent(_):
|
| 59 |
if df_global is None:
|
| 60 |
return "Please upload a file first.", []
|
|
@@ -74,10 +78,10 @@ def run_agent(_):
|
|
| 74 |
- Insightful relationships between key columns.
|
| 75 |
- At least 3 visualizations showing important trends.
|
| 76 |
4. Derive at least 3 actionable real-world insights.
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
"""
|
| 82 |
|
| 83 |
result = agent.run(
|
|
@@ -85,16 +89,16 @@ def run_agent(_):
|
|
| 85 |
additional_args={"source_file": temp_file.name}
|
| 86 |
)
|
| 87 |
|
| 88 |
-
#
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
-
insights = result_dict.get("insights", "No insights generated.")
|
| 94 |
-
image_paths = result_dict.get("figures", [])
|
| 95 |
-
return insights, image_paths
|
| 96 |
-
except Exception as e:
|
| 97 |
-
return f"Error parsing agent response: {e}", []
|
| 98 |
|
| 99 |
|
| 100 |
|
|
|
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
+
# Gradio Gallery and visualization output
|
| 59 |
+
visual_output = gr.Gallery(label="Generated Visualizations", columns=3, height=400)
|
| 60 |
+
|
| 61 |
+
# Fix in the `run_agent` function to handle agent results correctly
|
| 62 |
def run_agent(_):
|
| 63 |
if df_global is None:
|
| 64 |
return "Please upload a file first.", []
|
|
|
|
| 78 |
- Insightful relationships between key columns.
|
| 79 |
- At least 3 visualizations showing important trends.
|
| 80 |
4. Derive at least 3 actionable real-world insights.
|
| 81 |
+
5. Save all visualizations to ./figures/ directory.
|
| 82 |
+
Return a JSON object with keys:
|
| 83 |
+
- 'insights': clean bullet-point insights.
|
| 84 |
+
- 'figures': list of file paths of generated visualizations.
|
| 85 |
"""
|
| 86 |
|
| 87 |
result = agent.run(
|
|
|
|
| 89 |
additional_args={"source_file": temp_file.name}
|
| 90 |
)
|
| 91 |
|
| 92 |
+
# Process result as a dictionary if possible
|
| 93 |
+
if isinstance(result, dict):
|
| 94 |
+
insights = result.get("insights", "No insights generated.")
|
| 95 |
+
image_paths = result.get("figures", [])
|
| 96 |
+
else:
|
| 97 |
+
insights = "Error: The result is not in the expected format."
|
| 98 |
+
image_paths = []
|
| 99 |
+
|
| 100 |
+
return insights, image_paths
|
| 101 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
|
| 104 |
|