Update app.py
Browse files
app.py
CHANGED
@@ -178,12 +178,13 @@ Medical Records:
|
|
178 |
continue
|
179 |
|
180 |
if isinstance(chunk, list) and all(hasattr(m, 'role') and hasattr(m, 'content') for m in chunk):
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
elif isinstance(chunk, str):
|
186 |
-
|
|
|
187 |
yield history, None
|
188 |
|
189 |
report_path = os.path.join(report_dir, f"{file_hash_value}_report.txt") if file_hash_value else None
|
@@ -191,7 +192,7 @@ Medical Records:
|
|
191 |
|
192 |
except Exception as e:
|
193 |
print("🚨 ERROR:", e)
|
194 |
-
history
|
195 |
yield history, None
|
196 |
|
197 |
send_btn.click(analyze, inputs=[msg_input, gr.State([]), file_upload], outputs=[chatbot, download_output])
|
|
|
178 |
continue
|
179 |
|
180 |
if isinstance(chunk, list) and all(hasattr(m, 'role') and hasattr(m, 'content') for m in chunk):
|
181 |
+
for m in chunk:
|
182 |
+
cleaned_content = re.sub(r"\[TOOL_CALLS\].*?(?=(\[|\Z))", "", m.content, flags=re.DOTALL).strip()
|
183 |
+
history.append({"role": m.role, "content": cleaned_content or "⚠️ No answer returned."})
|
184 |
+
yield history, None
|
185 |
elif isinstance(chunk, str):
|
186 |
+
cleaned_chunk = re.sub(r"\[TOOL_CALLS\].*?(?=(\[|\Z))", "", chunk, flags=re.DOTALL).strip()
|
187 |
+
history[-1]["content"] += cleaned_chunk or "⚠️ No content generated."
|
188 |
yield history, None
|
189 |
|
190 |
report_path = os.path.join(report_dir, f"{file_hash_value}_report.txt") if file_hash_value else None
|
|
|
192 |
|
193 |
except Exception as e:
|
194 |
print("🚨 ERROR:", e)
|
195 |
+
history.append({"role": "assistant", "content": f"❌ Error occurred: {str(e)}"})
|
196 |
yield history, None
|
197 |
|
198 |
send_btn.click(analyze, inputs=[msg_input, gr.State([]), file_upload], outputs=[chatbot, download_output])
|