Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import os
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
import pandas as pd
|
| 4 |
import numpy as np
|
|
@@ -139,6 +140,23 @@ def format_insights(insights, visuals):
|
|
| 139 |
])
|
| 140 |
|
| 141 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
def analyze_data(csv_file, additional_notes=""):
|
| 143 |
start_time = time.time()
|
| 144 |
process = psutil.Process(os.getpid())
|
|
@@ -213,7 +231,14 @@ Be concise and avoid any narrative outside this final dictionary.
|
|
| 213 |
wandb.log({os.path.basename(viz): wandb.Image(viz)})
|
| 214 |
|
| 215 |
run.finish()
|
| 216 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
|
| 218 |
def compare_models():
|
| 219 |
import seaborn as sns
|
|
|
|
| 1 |
import os
|
| 2 |
+
import re
|
| 3 |
import gradio as gr
|
| 4 |
import pandas as pd
|
| 5 |
import numpy as np
|
|
|
|
| 140 |
])
|
| 141 |
|
| 142 |
|
| 143 |
+
def extract_json_from_codeagent_output(raw_output):
|
| 144 |
+
try:
|
| 145 |
+
# Try to extract just the json.dumps(...) output if the model followed instructions
|
| 146 |
+
match = re.search(r'json\.dumps\((.*?)\)\s*$', raw_output, re.DOTALL)
|
| 147 |
+
if match:
|
| 148 |
+
json_string = match.group(1)
|
| 149 |
+
# Attempt to load the inner Python dict
|
| 150 |
+
parsed_dict = eval(json_string) # Safe-ish since it’s model-generated
|
| 151 |
+
return parsed_dict
|
| 152 |
+
else:
|
| 153 |
+
# As fallback, try loading the whole string as JSON
|
| 154 |
+
return json.loads(raw_output)
|
| 155 |
+
except Exception as e:
|
| 156 |
+
print(f"[Error] Failed to parse agent output as JSON: {e}")
|
| 157 |
+
return None
|
| 158 |
+
|
| 159 |
+
|
| 160 |
def analyze_data(csv_file, additional_notes=""):
|
| 161 |
start_time = time.time()
|
| 162 |
process = psutil.Process(os.getpid())
|
|
|
|
| 231 |
wandb.log({os.path.basename(viz): wandb.Image(viz)})
|
| 232 |
|
| 233 |
run.finish()
|
| 234 |
+
parsed_result = extract_json_from_codeagent_output(analysis_result)
|
| 235 |
+
|
| 236 |
+
if parsed_result:
|
| 237 |
+
return format_analysis_report(parsed_result, visuals)
|
| 238 |
+
else:
|
| 239 |
+
# Fallback to showing the raw string if nothing worked
|
| 240 |
+
return f"<pre>{str(analysis_result)}</pre>", visuals
|
| 241 |
+
|
| 242 |
|
| 243 |
def compare_models():
|
| 244 |
import seaborn as sns
|