pavanmutha commited on
Commit
d815800
·
verified ·
1 Parent(s): d189610

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -21
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 "No data available. Please upload a file first."
60
-
61
- temp_path = "./temp_cleaned_data.csv"
62
- df_global.to_csv(temp_path, index=False)
63
-
64
- analysis_result = agent.run(
65
- """
66
- You are an expert data analyst. Perform comprehensive analysis including:
67
- 1. Basic statistics and data quality checks.
68
- 2. Three insightful analytical questions about relationships in the data.
69
- 3. Visualization of key patterns and correlations.
70
- 4. Actionable real-world insights derived from findings.
71
- Generate publication-quality visualizations and save them to './figures/'.
72
- """,
73
- additional_args={
74
- "additional_notes": additional_notes,
75
- "source_file": temp_path
76
- }
 
 
 
 
 
 
 
 
77
  )
78
 
79
- # print(analysis_result) # Safe to print here if you're debugging
80
- return analysis_result
 
 
 
 
 
 
 
 
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