Ali2206 commited on
Commit
5583dc0
·
verified ·
1 Parent(s): cb91f39

Update ui/ui_core.py

Browse files
Files changed (1) hide show
  1. ui/ui_core.py +13 -6
ui/ui_core.py CHANGED
@@ -21,19 +21,18 @@ 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
  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,7 +51,7 @@ def extract_all_text_from_pdf(file_path, progress=None, index=0, total=1):
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
 
@@ -97,6 +96,7 @@ def create_ui(agent: TxAgent):
97
 
98
  message = f"{context}\n\n---\n{extracted_text.strip()}\n---\n\nBegin your reasoning."
99
 
 
100
  generator = agent.run_gradio_chat(
101
  message=message,
102
  history=history,
@@ -109,7 +109,14 @@ def create_ui(agent: TxAgent):
109
  max_round=30
110
  )
111
  for update in generator:
112
- yield update
 
 
 
 
 
 
 
113
 
114
  inputs = [message_input, chatbot, conversation_state, file_upload]
115
  send_button.click(fn=handle_chat, inputs=inputs, outputs=chatbot)
 
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
  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
 
 
96
 
97
  message = f"{context}\n\n---\n{extracted_text.strip()}\n---\n\nBegin your reasoning."
98
 
99
+ final_response = None
100
  generator = agent.run_gradio_chat(
101
  message=message,
102
  history=history,
 
109
  max_round=30
110
  )
111
  for update in generator:
112
+ if isinstance(update, list):
113
+ cleaned = [msg for msg in update if not (msg.role == "assistant" and msg.content.strip().startswith("🧰"))]
114
+ if cleaned:
115
+ final_response = cleaned
116
+ yield cleaned
117
+ else:
118
+ if isinstance(update, str) and not update.strip().startswith("🧰"):
119
+ yield update
120
 
121
  inputs = [message_input, chatbot, conversation_state, file_upload]
122
  send_button.click(fn=handle_chat, inputs=inputs, outputs=chatbot)