Update ui/ui_core.py
Browse files- ui/ui_core.py +8 -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 |
from typing import List
|
7 |
|
8 |
# ✅ Fix: Add src to Python path
|
@@ -10,6 +11,9 @@ sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..",
|
|
10 |
|
11 |
from txagent.txagent import TxAgent
|
12 |
|
|
|
|
|
|
|
13 |
def extract_all_text_from_csv_or_excel(file_path: str, progress=None, index=0, total=1) -> str:
|
14 |
try:
|
15 |
if not os.path.exists(file_path):
|
@@ -100,8 +104,9 @@ def create_ui(agent: TxAgent):
|
|
100 |
extracted_text += f"[Error processing file: {os.path.basename(path)}] — {str(file_error)}\n"
|
101 |
continue
|
102 |
|
|
|
103 |
message = (
|
104 |
-
f"{context}\n\n--- Uploaded File Content ---\n\n{
|
105 |
)
|
106 |
|
107 |
generator = agent.run_gradio_chat(
|
@@ -131,7 +136,7 @@ def create_ui(agent: TxAgent):
|
|
131 |
if cleaned:
|
132 |
yield cleaned
|
133 |
elif isinstance(update, str) and not update.strip().startswith("\ud83e\udde0"):
|
134 |
-
yield update.encode("utf-8", "replace").decode("utf-8")
|
135 |
except Exception as update_error:
|
136 |
print(f"Error processing update: {update_error}")
|
137 |
continue
|
@@ -150,4 +155,4 @@ def create_ui(agent: TxAgent):
|
|
150 |
["Is there anything abnormal in the attached blood work report?"]
|
151 |
], inputs=message_input)
|
152 |
|
153 |
-
return demo
|
|
|
3 |
import pandas as pd
|
4 |
import pdfplumber
|
5 |
import gradio as gr
|
6 |
+
import re
|
7 |
from typing import List
|
8 |
|
9 |
# ✅ Fix: Add src to Python path
|
|
|
11 |
|
12 |
from txagent.txagent import TxAgent
|
13 |
|
14 |
+
def sanitize_utf8(text: str) -> str:
|
15 |
+
return re.sub(r'[\ud800-\udfff]', '', text)
|
16 |
+
|
17 |
def extract_all_text_from_csv_or_excel(file_path: str, progress=None, index=0, total=1) -> str:
|
18 |
try:
|
19 |
if not os.path.exists(file_path):
|
|
|
104 |
extracted_text += f"[Error processing file: {os.path.basename(path)}] — {str(file_error)}\n"
|
105 |
continue
|
106 |
|
107 |
+
sanitized = sanitize_utf8(extracted_text.strip())
|
108 |
message = (
|
109 |
+
f"{context}\n\n--- Uploaded File Content ---\n\n{sanitized}\n\n--- End of File ---\n\nNow begin your reasoning:"
|
110 |
)
|
111 |
|
112 |
generator = agent.run_gradio_chat(
|
|
|
136 |
if cleaned:
|
137 |
yield cleaned
|
138 |
elif isinstance(update, str) and not update.strip().startswith("\ud83e\udde0"):
|
139 |
+
yield sanitize_utf8(update.encode("utf-8", "replace").decode("utf-8"))
|
140 |
except Exception as update_error:
|
141 |
print(f"Error processing update: {update_error}")
|
142 |
continue
|
|
|
155 |
["Is there anything abnormal in the attached blood work report?"]
|
156 |
], inputs=message_input)
|
157 |
|
158 |
+
return demo
|