DrishtiSharma commited on
Commit
90a78f2
·
verified ·
1 Parent(s): 2ef41d6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -10
app.py CHANGED
@@ -450,7 +450,6 @@ def display_table(analyst_output):
450
  category = item["Category"]
451
  values = item["Values"]
452
 
453
- # Error handling to prevent crashes
454
  try:
455
  # Handle dictionary data (Table View)
456
  if isinstance(values, dict):
@@ -459,28 +458,38 @@ def display_table(analyst_output):
459
  st.dataframe(df)
460
  table_data.extend(df.to_dict(orient="records"))
461
 
462
- # Handle list data (List View)
463
  elif isinstance(values, list):
464
- df = pd.DataFrame(values, columns=["Items"])
465
- st.subheader(f"{category} (List View)")
466
- st.dataframe(df)
467
- table_data.extend(df.to_dict(orient="records"))
 
 
 
 
 
 
 
 
468
 
469
- # Handle text data (Summary View)
470
  elif isinstance(values, str):
471
  st.subheader(f"{category} (Summary)")
472
  st.table(pd.DataFrame({"Insights": [values]}))
473
  table_data.append({"Category": category, "Values": values})
474
 
475
  else:
476
- st.warning(f"Unsupported data format for category: {category}")
 
477
 
478
  except Exception as e:
479
- logging.error(f"Error processing {category}: {e}")
480
- st.error(f"Failed to display {category} as a table due to an error.")
481
 
482
  return table_data
483
 
 
484
  def parse_analyst_output(raw_output):
485
  key_insights = []
486
  data_insights = []
 
450
  category = item["Category"]
451
  values = item["Values"]
452
 
 
453
  try:
454
  # Handle dictionary data (Table View)
455
  if isinstance(values, dict):
 
458
  st.dataframe(df)
459
  table_data.extend(df.to_dict(orient="records"))
460
 
461
+ # Handle list data
462
  elif isinstance(values, list):
463
+ # Handle complex lists (list of dictionaries)
464
+ if all(isinstance(v, dict) for v in values):
465
+ df = pd.DataFrame(values)
466
+ st.subheader(f"{category} (Detailed View)")
467
+ st.dataframe(df)
468
+ table_data.extend(df.to_dict(orient="records"))
469
+ # Handle simple lists
470
+ else:
471
+ df = pd.DataFrame(values, columns=["Items"])
472
+ st.subheader(f"{category} (List View)")
473
+ st.dataframe(df)
474
+ table_data.extend(df.to_dict(orient="records"))
475
 
476
+ # Handle text data
477
  elif isinstance(values, str):
478
  st.subheader(f"{category} (Summary)")
479
  st.table(pd.DataFrame({"Insights": [values]}))
480
  table_data.append({"Category": category, "Values": values})
481
 
482
  else:
483
+ st.warning(f"Unsupported data format for {category}")
484
+ logging.warning(f"Unsupported data in {category}: {values}")
485
 
486
  except Exception as e:
487
+ st.error(f"Error displaying {category}: {e}")
488
+ logging.error(f"Display error for {category}: {e}")
489
 
490
  return table_data
491
 
492
+
493
  def parse_analyst_output(raw_output):
494
  key_insights = []
495
  data_insights = []