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

Update ui/ui_core.py

Browse files
Files changed (1) hide show
  1. ui/ui_core.py +19 -3
ui/ui_core.py CHANGED
@@ -3,6 +3,7 @@ import os
3
  import pandas as pd
4
  import pdfplumber
5
  import gradio as gr
 
6
 
7
  # ✅ Add src to Python path
8
  sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src")))
@@ -16,9 +17,24 @@ def extract_all_text_from_csv_or_excel(file_path, progress=None, index=0, total=
16
  df = pd.read_excel(file_path)
17
  else:
18
  return f"Unsupported spreadsheet format: {file_path}"
 
19
  if progress:
20
  progress((index + 1) / total, desc=f"Processed table: {os.path.basename(file_path)}")
21
- return df.to_string(index=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  except Exception as e:
23
  return f"Error parsing file: {e}"
24
 
@@ -41,7 +57,7 @@ def extract_all_text_from_pdf(file_path, progress=None, index=0, total=1):
41
 
42
  def create_ui(agent: TxAgent):
43
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
44
- gr.Markdown("<h1 style='text-align: center;'>\ud83d\udccb CPS: Clinical Patient Support System</h1>")
45
  chatbot = gr.Chatbot(label="CPS Assistant", height=600, type="messages")
46
 
47
  file_upload = gr.File(
@@ -104,4 +120,4 @@ def create_ui(agent: TxAgent):
104
  ["Is there anything abnormal in the attached blood work report?"]
105
  ], inputs=message_input)
106
 
107
- return demo
 
3
  import pandas as pd
4
  import pdfplumber
5
  import gradio as gr
6
+ from tabulate import tabulate
7
 
8
  # ✅ Add src to Python path
9
  sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src")))
 
17
  df = pd.read_excel(file_path)
18
  else:
19
  return f"Unsupported spreadsheet format: {file_path}"
20
+
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:
39
  return f"Error parsing file: {e}"
40
 
 
57
 
58
  def create_ui(agent: TxAgent):
59
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
60
+ gr.Markdown("<h1 style='text-align: center;'>📋 CPS: Clinical Patient Support System</h1>")
61
  chatbot = gr.Chatbot(label="CPS Assistant", height=600, type="messages")
62
 
63
  file_upload = gr.File(
 
120
  ["Is there anything abnormal in the attached blood work report?"]
121
  ], inputs=message_input)
122
 
123
+ return demo