Spaces:
Sleeping
Sleeping
Nyha15 commited on
Commit ·
84900a9
1
Parent(s): b20e398
Fixed html
Browse files
app.py
CHANGED
|
@@ -1234,29 +1234,38 @@ def run_data_analysis(dataset_url, llm_provider, api_key, missing_strategy, crea
|
|
| 1234 |
|
| 1235 |
# Get the final report
|
| 1236 |
report_html = "<h2>No report generated</h2>"
|
| 1237 |
-
|
| 1238 |
-
|
| 1239 |
-
|
| 1240 |
-
|
| 1241 |
-
|
| 1242 |
-
|
| 1243 |
-
|
| 1244 |
-
|
| 1245 |
-
|
| 1246 |
-
|
| 1247 |
-
|
| 1248 |
-
|
| 1249 |
-
|
| 1250 |
-
|
| 1251 |
-
|
| 1252 |
-
|
| 1253 |
-
|
| 1254 |
-
|
| 1255 |
-
|
| 1256 |
-
|
| 1257 |
-
|
| 1258 |
-
|
| 1259 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1260 |
|
| 1261 |
# Return all results
|
| 1262 |
return {
|
|
@@ -1268,11 +1277,12 @@ def run_data_analysis(dataset_url, llm_provider, api_key, missing_strategy, crea
|
|
| 1268 |
|
| 1269 |
except Exception as e:
|
| 1270 |
import traceback
|
|
|
|
| 1271 |
return {
|
| 1272 |
-
'mcp_messages': f"Error: {str(e)}\n\n{
|
| 1273 |
'llm_logs': "",
|
| 1274 |
'visualizations': "",
|
| 1275 |
-
'final_report': ""
|
| 1276 |
}
|
| 1277 |
|
| 1278 |
# Define the Gradio interface
|
|
|
|
| 1234 |
|
| 1235 |
# Get the final report
|
| 1236 |
report_html = "<h2>No report generated</h2>"
|
| 1237 |
+
|
| 1238 |
+
# Check if report result exists
|
| 1239 |
+
report_found = False
|
| 1240 |
+
for msg in compute_messages:
|
| 1241 |
+
if msg["type"] == "received" and msg["message"]["message_type"] == "report_result":
|
| 1242 |
+
report_found = True
|
| 1243 |
+
try:
|
| 1244 |
+
if "content" in msg["message"] and "report" in msg["message"]["content"]:
|
| 1245 |
+
report_content = msg["message"]["content"]["report"]
|
| 1246 |
+
if "content" in report_content:
|
| 1247 |
+
# LLM-generated report
|
| 1248 |
+
report_html = f"<h2>{report_content['title']}</h2>"
|
| 1249 |
+
newline_replaced = report_content['content'].replace("\n", "<br>")
|
| 1250 |
+
report_html += f"<div>{newline_replaced}</div>"
|
| 1251 |
+
elif "sections" in report_content:
|
| 1252 |
+
# Template-based report
|
| 1253 |
+
report_html = f"<h2>{report_content['title']}</h2>"
|
| 1254 |
+
for section in report_content["sections"]:
|
| 1255 |
+
report_html += f"<h3>{section['title']}</h3>"
|
| 1256 |
+
report_html += f"<p>{section['content']}</p>"
|
| 1257 |
+
if "insights" in section:
|
| 1258 |
+
report_html += "<ul>"
|
| 1259 |
+
for insight in section["insights"]:
|
| 1260 |
+
report_html += f"<li>{insight}</li>"
|
| 1261 |
+
report_html += "</ul>"
|
| 1262 |
+
if "data" in section:
|
| 1263 |
+
report_html += "<pre>" + format_json(section["data"]) + "</pre>"
|
| 1264 |
+
except Exception as e:
|
| 1265 |
+
report_html = f"<h2>Error generating report: {str(e)}</h2>"
|
| 1266 |
+
|
| 1267 |
+
if not report_found:
|
| 1268 |
+
report_html = "<h2>No report message received</h2>"
|
| 1269 |
|
| 1270 |
# Return all results
|
| 1271 |
return {
|
|
|
|
| 1277 |
|
| 1278 |
except Exception as e:
|
| 1279 |
import traceback
|
| 1280 |
+
error_traceback = traceback.format_exc()
|
| 1281 |
return {
|
| 1282 |
+
'mcp_messages': f"Error: {str(e)}\n\n{error_traceback}",
|
| 1283 |
'llm_logs': "",
|
| 1284 |
'visualizations': "",
|
| 1285 |
+
'final_report': f"<h2>Error: {str(e)}</h2><pre>{error_traceback}</pre>"
|
| 1286 |
}
|
| 1287 |
|
| 1288 |
# Define the Gradio interface
|