Update ui/ui_core.py
Browse files- ui/ui_core.py +12 -9
ui/ui_core.py
CHANGED
@@ -20,14 +20,15 @@ def clean_final_response(text: str) -> str:
|
|
20 |
if len(responses) <= 1:
|
21 |
return f"<div style='padding:1em;border:1px solid #ccc;border-radius:12px;color:#fff;background:#353F54;'><p>{cleaned}</p></div>"
|
22 |
|
|
|
23 |
panels = []
|
24 |
for i, section in enumerate(responses[1:], 1):
|
25 |
final = section.strip()
|
26 |
panels.append(
|
27 |
-
f"<
|
28 |
-
f"<
|
29 |
f"<div style='padding:1em;line-height:1.6;'>{final.replace(chr(10), '<br>')}</div>"
|
30 |
-
f"</
|
31 |
)
|
32 |
return "".join(panels)
|
33 |
|
@@ -41,21 +42,21 @@ def extract_all_text_from_csv_or_excel(file_path: str, progress=None, index=0, t
|
|
41 |
|
42 |
df = None
|
43 |
if file_path.endswith(".csv"):
|
44 |
-
df = pd.read_csv(file_path, encoding_errors="replace")
|
45 |
elif file_path.endswith((".xls", ".xlsx")):
|
46 |
-
|
47 |
-
|
48 |
-
|
|
|
49 |
|
50 |
if df is None or df.empty:
|
51 |
-
return f"
|
52 |
|
53 |
lines = []
|
54 |
for _, row in df.iterrows():
|
55 |
line = " | ".join(str(cell) for cell in row if pd.notna(cell))
|
56 |
if line:
|
57 |
lines.append(line)
|
58 |
-
|
59 |
return f"\U0001F4C4 {os.path.basename(file_path)}\n\n" + "\n".join(lines)
|
60 |
|
61 |
except Exception as e:
|
@@ -99,6 +100,8 @@ def chunk_text(text: str, max_tokens: int = 8192) -> List[str]:
|
|
99 |
chunks.append(" ".join(chunk))
|
100 |
return chunks
|
101 |
|
|
|
|
|
102 |
def create_ui(agent: TxAgent):
|
103 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
104 |
gr.Markdown("<h1 style='text-align: center;'>\U0001F4CB CPS: Clinical Patient Support System</h1>")
|
|
|
20 |
if len(responses) <= 1:
|
21 |
return f"<div style='padding:1em;border:1px solid #ccc;border-radius:12px;color:#fff;background:#353F54;'><p>{cleaned}</p></div>"
|
22 |
|
23 |
+
# Support multiple [Final Analysis] sections
|
24 |
panels = []
|
25 |
for i, section in enumerate(responses[1:], 1):
|
26 |
final = section.strip()
|
27 |
panels.append(
|
28 |
+
f"<div style='background:#2B2B2B;color:#E0E0E0;border-radius:12px;margin-bottom:1em;border:1px solid #888;'>"
|
29 |
+
f"<div style='font-size:1.1em;font-weight:bold;padding:0.75em;background:#3A3A3A;color:#fff;border-radius:12px 12px 0 0;'>🧠 Final Analysis #{i}</div>"
|
30 |
f"<div style='padding:1em;line-height:1.6;'>{final.replace(chr(10), '<br>')}</div>"
|
31 |
+
f"</div>"
|
32 |
)
|
33 |
return "".join(panels)
|
34 |
|
|
|
42 |
|
43 |
df = None
|
44 |
if file_path.endswith(".csv"):
|
45 |
+
df = pd.read_csv(file_path, encoding_errors="replace", dtype=str, header=None)
|
46 |
elif file_path.endswith((".xls", ".xlsx")):
|
47 |
+
try:
|
48 |
+
df = pd.read_excel(file_path, engine="openpyxl", dtype=str, header=None)
|
49 |
+
except:
|
50 |
+
df = pd.read_excel(file_path, engine="xlrd", dtype=str, header=None)
|
51 |
|
52 |
if df is None or df.empty:
|
53 |
+
return f"[Warning] No data extracted from: {file_path}"
|
54 |
|
55 |
lines = []
|
56 |
for _, row in df.iterrows():
|
57 |
line = " | ".join(str(cell) for cell in row if pd.notna(cell))
|
58 |
if line:
|
59 |
lines.append(line)
|
|
|
60 |
return f"\U0001F4C4 {os.path.basename(file_path)}\n\n" + "\n".join(lines)
|
61 |
|
62 |
except Exception as e:
|
|
|
100 |
chunks.append(" ".join(chunk))
|
101 |
return chunks
|
102 |
|
103 |
+
# ... rest of the UI code remains unchanged
|
104 |
+
|
105 |
def create_ui(agent: TxAgent):
|
106 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
107 |
gr.Markdown("<h1 style='text-align: center;'>\U0001F4CB CPS: Clinical Patient Support System</h1>")
|