Ali2206 commited on
Commit
ed59741
·
verified ·
1 Parent(s): ff7a915

Update ui/ui_core.py

Browse files
Files changed (1) hide show
  1. ui/ui_core.py +6 -5
ui/ui_core.py CHANGED
@@ -21,18 +21,19 @@ def extract_all_text_from_csv_or_excel(file_path, progress=None, index=0, total=
21
  if progress:
22
  progress((index + 1) / total, desc=f"Processed table: {os.path.basename(file_path)}")
23
 
24
- # Group by "Booking Number" or "Form Name" if available
25
  if "Booking Number" in df.columns:
26
  groups = df.groupby("Booking Number")
27
  elif "Form Name" in df.columns:
28
  groups = df.groupby("Form Name")
29
  else:
30
- return tabulate(df, headers="keys", tablefmt="github", showindex=False)
31
 
32
  result = []
33
  for group_name, group_df in groups:
34
  result.append(f"\n### Group: {group_name}\n")
35
- result.append(tabulate(group_df, headers="keys", tablefmt="github", showindex=False))
 
 
36
  return "\n".join(result)
37
 
38
  except Exception as e:
@@ -51,7 +52,7 @@ def extract_all_text_from_pdf(file_path, progress=None, index=0, total=1):
51
  extracted.append("\t".join([cell or "" for cell in row]))
52
  if progress:
53
  progress((index + i / num_pages) / total, desc=f"Parsing PDF: {os.path.basename(file_path)} ({i+1}/{num_pages})")
54
- return "\n".join(extracted)
55
  except Exception as e:
56
  return f"Error parsing PDF: {e}"
57
 
@@ -120,4 +121,4 @@ def create_ui(agent: TxAgent):
120
  ["Is there anything abnormal in the attached blood work report?"]
121
  ], inputs=message_input)
122
 
123
- return demo
 
21
  if progress:
22
  progress((index + 1) / total, desc=f"Processed table: {os.path.basename(file_path)}")
23
 
 
24
  if "Booking Number" in df.columns:
25
  groups = df.groupby("Booking Number")
26
  elif "Form Name" in df.columns:
27
  groups = df.groupby("Form Name")
28
  else:
29
+ return tabulate(df, headers="keys", tablefmt="github", showindex=False).encode("utf-8", errors="replace").decode("utf-8")
30
 
31
  result = []
32
  for group_name, group_df in groups:
33
  result.append(f"\n### Group: {group_name}\n")
34
+ formatted = tabulate(group_df, headers="keys", tablefmt="github", showindex=False)
35
+ result.append(formatted.encode("utf-8", errors="replace").decode("utf-8"))
36
+
37
  return "\n".join(result)
38
 
39
  except Exception as e:
 
52
  extracted.append("\t".join([cell or "" for cell in row]))
53
  if progress:
54
  progress((index + i / num_pages) / total, desc=f"Parsing PDF: {os.path.basename(file_path)} ({i+1}/{num_pages})")
55
+ return "\n".join(extracted).encode("utf-8", errors="replace").decode("utf-8")
56
  except Exception as e:
57
  return f"Error parsing PDF: {e}"
58
 
 
121
  ["Is there anything abnormal in the attached blood work report?"]
122
  ], inputs=message_input)
123
 
124
+ return demo