Nyha15 commited on
Commit
84900a9
·
1 Parent(s): b20e398

Fixed html

Browse files
Files changed (1) hide show
  1. app.py +35 -25
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
- if "report_result" in [msg["message"]["message_type"] for msg in compute_messages if msg["type"] == "received"]:
1238
- # Find the report message
1239
- for msg in compute_messages:
1240
- if msg["type"] == "received" and msg["message"]["message_type"] == "report_result":
1241
- report_content = msg["message"]["content"]["report"]
1242
- if "content" in report_content:
1243
- # LLM-generated report
1244
- report_html = f"<h2>{report_content['title']}</h2>"
1245
- newline_replaced = report_content['content'].replace("\n", "<br>")
1246
- report_html += f"<div>{newline_replaced}</div>"
1247
- elif "sections" in report_content:
1248
- # Template-based report
1249
- report_html = f"<h2>{report_content['title']}</h2>"
1250
- for section in report_content["sections"]:
1251
- report_html += f"<h3>{section['title']}</h3>"
1252
- report_html += f"<p>{section['content']}</p>"
1253
- if "insights" in section:
1254
- report_html += "<ul>"
1255
- for insight in section["insights"]:
1256
- report_html += f"<li>{insight}</li>"
1257
- report_html += "</ul>"
1258
- if "data" in section:
1259
- report_html += "<pre>" + format_json(section["data"]) + "</pre>"
 
 
 
 
 
 
 
 
 
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{traceback.format_exc()}",
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