DrishtiSharma commited on
Commit
d50ae2c
·
verified ·
1 Parent(s): f81f2af

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -5
app.py CHANGED
@@ -495,31 +495,39 @@ def parse_analyst_output(raw_output):
495
  data_insights = []
496
 
497
  try:
498
- # Correctly parse the raw output
499
  structured_data = ast.literal_eval(raw_output) if isinstance(raw_output, str) else raw_output
500
 
501
  for item in structured_data:
502
  if "Category" not in item or "Values" not in item:
503
  logging.warning(f"Missing 'Category' or 'Values' in item: {item}")
504
- continue
505
 
506
  if item.get("Type") == "Key Insight":
507
  key_insights.append(item["Values"])
 
508
  elif item.get("Type") == "Data Insight":
509
- # Handle nested structures (e.g., Technology Spotlight Cards)
510
  if isinstance(item["Values"], list):
511
  for sub_item in item["Values"]:
512
- data_insights.append({"Category": item["Category"], "Values": sub_item})
 
 
 
 
 
513
  else:
514
  data_insights.append(item)
 
515
  else:
516
- data_insights.append(item)
517
 
518
  except Exception as e:
519
  logging.error(f"Error parsing analyst output: {e}")
520
 
521
  return key_insights, data_insights
522
 
 
523
  # Main Execution Block
524
  # Initialize placeholders for outputs to ensure tabs are always visible
525
  planner_output = "Planner insights will appear here after generating insights."
 
495
  data_insights = []
496
 
497
  try:
498
+ # Parse string to Python object if needed
499
  structured_data = ast.literal_eval(raw_output) if isinstance(raw_output, str) else raw_output
500
 
501
  for item in structured_data:
502
  if "Category" not in item or "Values" not in item:
503
  logging.warning(f"Missing 'Category' or 'Values' in item: {item}")
504
+ continue
505
 
506
  if item.get("Type") == "Key Insight":
507
  key_insights.append(item["Values"])
508
+
509
  elif item.get("Type") == "Data Insight":
510
+ # Flatten nested dictionary structures for visualization
511
  if isinstance(item["Values"], list):
512
  for sub_item in item["Values"]:
513
+ if isinstance(sub_item, dict):
514
+ data_insights.append({"Category": item["Category"], "Values": sub_item})
515
+ else:
516
+ data_insights.append({"Category": item["Category"], "Values": sub_item})
517
+ elif isinstance(item["Values"], dict):
518
+ data_insights.append(item)
519
  else:
520
  data_insights.append(item)
521
+
522
  else:
523
+ logging.warning(f"Unrecognized Type in item: {item}")
524
 
525
  except Exception as e:
526
  logging.error(f"Error parsing analyst output: {e}")
527
 
528
  return key_insights, data_insights
529
 
530
+
531
  # Main Execution Block
532
  # Initialize placeholders for outputs to ensure tabs are always visible
533
  planner_output = "Planner insights will appear here after generating insights."