DrishtiSharma commited on
Commit
d42a10c
·
verified ·
1 Parent(s): e646334

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -6
app.py CHANGED
@@ -316,20 +316,46 @@ def display_table(analyst_output):
316
  def parse_analyst_output(raw_output):
317
  structured_data = []
318
  current_category = None
 
319
 
320
  lines = raw_output.split('\n')
321
-
322
  for line in lines:
323
  line = line.strip()
 
 
324
  if line.startswith("Category:"):
 
 
 
 
 
 
 
325
  current_category = line.replace("Category:", "").strip()
 
 
 
326
  elif line.startswith("Values:"):
327
- continue
 
 
328
  elif line and current_category:
329
- structured_data.append({
330
- "Category": current_category,
331
- "Values": line
332
- })
 
 
 
 
 
 
 
 
 
 
 
333
  return structured_data
334
 
335
 
 
316
  def parse_analyst_output(raw_output):
317
  structured_data = []
318
  current_category = None
319
+ current_values = []
320
 
321
  lines = raw_output.split('\n')
322
+
323
  for line in lines:
324
  line = line.strip()
325
+
326
+ # Detect new category
327
  if line.startswith("Category:"):
328
+ # Save previous category if exists
329
+ if current_category and current_values:
330
+ structured_data.append({
331
+ "Category": current_category,
332
+ "Values": current_values if len(current_values) > 1 else current_values[0]
333
+ })
334
+ # Start new category
335
  current_category = line.replace("Category:", "").strip()
336
+ current_values = []
337
+
338
+ # Detect start of values
339
  elif line.startswith("Values:"):
340
+ continue
341
+
342
+ # Handle content under a category
343
  elif line and current_category:
344
+ try:
345
+ # Attempt to parse the line as a dictionary or list
346
+ parsed_value = ast.literal_eval(line)
347
+ current_values.append(parsed_value)
348
+ except (ValueError, SyntaxError):
349
+ # If parsing fails, treat it as plain text
350
+ current_values.append(line)
351
+
352
+ # Save the last category
353
+ if current_category and current_values:
354
+ structured_data.append({
355
+ "Category": current_category,
356
+ "Values": current_values if len(current_values) > 1 else current_values[0]
357
+ })
358
+
359
  return structured_data
360
 
361