Update app.py
Browse files
app.py
CHANGED
|
@@ -54,30 +54,45 @@ agent = CodeAgent(
|
|
| 54 |
)
|
| 55 |
|
| 56 |
def run_agent(_):
|
| 57 |
-
global df_global
|
| 58 |
if df_global is None:
|
| 59 |
-
return "
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
)
|
| 78 |
|
| 79 |
-
|
| 80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
|
| 83 |
|
|
|
|
| 54 |
)
|
| 55 |
|
| 56 |
def run_agent(_):
|
|
|
|
| 57 |
if df_global is None:
|
| 58 |
+
return "Please upload a file first."
|
| 59 |
+
|
| 60 |
+
from tempfile import NamedTemporaryFile
|
| 61 |
+
temp_file = NamedTemporaryFile(delete=False, suffix=".csv")
|
| 62 |
+
df_global.to_csv(temp_file.name, index=False)
|
| 63 |
+
temp_file.close()
|
| 64 |
+
|
| 65 |
+
prompt = """
|
| 66 |
+
You are an expert data analyst.
|
| 67 |
+
1. Load the provided dataset and analyze the structure.
|
| 68 |
+
2. Automatically detect key numeric and categorical columns.
|
| 69 |
+
3. Perform:
|
| 70 |
+
- Basic descriptive statistics.
|
| 71 |
+
- Null and duplicate checks.
|
| 72 |
+
- Insightful relationships between key columns.
|
| 73 |
+
- At least 3 visualizations showing important trends.
|
| 74 |
+
4. Derive at least 3 actionable real-world insights.
|
| 75 |
+
5. Save all visualizations to ./figures/ directory.
|
| 76 |
+
Return:
|
| 77 |
+
- A summary of the insights in clean bullet-point format.
|
| 78 |
+
- File paths of the generated visualizations.
|
| 79 |
+
"""
|
| 80 |
+
|
| 81 |
+
result = agent.run(
|
| 82 |
+
prompt,
|
| 83 |
+
additional_args={"source_file": temp_file.name}
|
| 84 |
)
|
| 85 |
|
| 86 |
+
# Extract image paths from output (assuming SmolAgent prints them)
|
| 87 |
+
image_paths = []
|
| 88 |
+
for line in result.splitlines():
|
| 89 |
+
if line.strip().endswith(".png"):
|
| 90 |
+
image_paths.append(line.strip())
|
| 91 |
+
|
| 92 |
+
insights = "\n".join([line for line in result.splitlines() if not line.strip().endswith(".png")])
|
| 93 |
+
|
| 94 |
+
return insights, image_paths
|
| 95 |
+
|
| 96 |
|
| 97 |
|
| 98 |
|