DrishtiSharma commited on
Commit
60b86da
·
verified ·
1 Parent(s): 8579f41

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -3
app.py CHANGED
@@ -472,24 +472,32 @@ def parse_analyst_output(raw_output):
472
  data_insights = []
473
 
474
  try:
 
475
  structured_data = ast.literal_eval(raw_output) if isinstance(raw_output, str) else raw_output
476
 
477
  for item in structured_data:
478
- if "Category" not in item:
479
- logging.warning(f"Missing 'Category' in item: {item}")
480
  continue
481
 
482
  if item.get("Type") == "Key Insight":
483
  key_insights.append(item["Values"])
484
  elif item.get("Type") == "Data Insight":
485
- data_insights.append(item)
 
 
 
 
 
486
  else:
487
  data_insights.append(item)
 
488
  except Exception as e:
489
  logging.error(f"Error parsing analyst output: {e}")
490
 
491
  return key_insights, data_insights
492
 
 
493
  # Main Execution Block
494
  if st.button("Generate Patent Insights"):
495
  with st.spinner('Processing...'):
 
472
  data_insights = []
473
 
474
  try:
475
+ # Correctly parse the raw output
476
  structured_data = ast.literal_eval(raw_output) if isinstance(raw_output, str) else raw_output
477
 
478
  for item in structured_data:
479
+ if "Category" not in item or "Values" not in item:
480
+ logging.warning(f"Missing 'Category' or 'Values' in item: {item}")
481
  continue
482
 
483
  if item.get("Type") == "Key Insight":
484
  key_insights.append(item["Values"])
485
  elif item.get("Type") == "Data Insight":
486
+ # Handle nested structures (e.g., Technology Spotlight Cards)
487
+ if isinstance(item["Values"], list):
488
+ for sub_item in item["Values"]:
489
+ data_insights.append({"Category": item["Category"], "Values": sub_item})
490
+ else:
491
+ data_insights.append(item)
492
  else:
493
  data_insights.append(item)
494
+
495
  except Exception as e:
496
  logging.error(f"Error parsing analyst output: {e}")
497
 
498
  return key_insights, data_insights
499
 
500
+
501
  # Main Execution Block
502
  if st.button("Generate Patent Insights"):
503
  with st.spinner('Processing...'):