Update app.py
Browse files
app.py
CHANGED
|
@@ -126,9 +126,9 @@ def init_agent():
|
|
| 126 |
return agent
|
| 127 |
|
| 128 |
|
| 129 |
-
def stream_final_report(agent, file) -> Generator[List[Dict[str, str]], None, None]:
|
| 130 |
if file is None or not hasattr(file, "name"):
|
| 131 |
-
yield [{"role": "assistant", "content":
|
| 132 |
return
|
| 133 |
|
| 134 |
extracted_text = extract_text_from_excel(file.name)
|
|
@@ -158,7 +158,7 @@ def stream_final_report(agent, file) -> Generator[List[Dict[str, str]], None, No
|
|
| 158 |
chunk_responses.append(clean_response(response))
|
| 159 |
|
| 160 |
final_prompt = "\n\n".join(chunk_responses) + "\n\nSummarize the key findings above."
|
| 161 |
-
|
| 162 |
stream_text = ""
|
| 163 |
for result in agent.run_gradio_chat(
|
| 164 |
message=final_prompt,
|
|
@@ -177,14 +177,16 @@ def stream_final_report(agent, file) -> Generator[List[Dict[str, str]], None, No
|
|
| 177 |
for r in result:
|
| 178 |
if hasattr(r, "content"):
|
| 179 |
stream_text += r.content
|
| 180 |
-
|
|
|
|
| 181 |
|
| 182 |
final_report = f"# \U0001f9e0 Final Patient Report\n\n{clean_response(stream_text)}"
|
| 183 |
report_path = os.path.join(report_dir, f"report_{datetime.now().strftime('%Y%m%d_%H%M%S')}.md")
|
| 184 |
with open(report_path, 'w') as f:
|
| 185 |
f.write(final_report)
|
| 186 |
|
| 187 |
-
|
|
|
|
| 188 |
|
| 189 |
|
| 190 |
def create_ui(agent):
|
|
@@ -215,4 +217,4 @@ if __name__ == "__main__":
|
|
| 215 |
)
|
| 216 |
except Exception as e:
|
| 217 |
print(f"Error: {str(e)}")
|
| 218 |
-
sys.exit(1)
|
|
|
|
| 126 |
return agent
|
| 127 |
|
| 128 |
|
| 129 |
+
def stream_final_report(agent, file) -> Generator[Tuple[List[Dict[str, str]], str], None, None]:
|
| 130 |
if file is None or not hasattr(file, "name"):
|
| 131 |
+
yield ([{"role": "assistant", "content": "❌ Please upload a valid Excel file before analyzing."}], "")
|
| 132 |
return
|
| 133 |
|
| 134 |
extracted_text = extract_text_from_excel(file.name)
|
|
|
|
| 158 |
chunk_responses.append(clean_response(response))
|
| 159 |
|
| 160 |
final_prompt = "\n\n".join(chunk_responses) + "\n\nSummarize the key findings above."
|
| 161 |
+
messages = [{"role": "user", "content": f"[Excel Uploaded: {file.name}]"}]
|
| 162 |
stream_text = ""
|
| 163 |
for result in agent.run_gradio_chat(
|
| 164 |
message=final_prompt,
|
|
|
|
| 177 |
for r in result:
|
| 178 |
if hasattr(r, "content"):
|
| 179 |
stream_text += r.content
|
| 180 |
+
messages.append({"role": "assistant", "content": clean_response(stream_text)})
|
| 181 |
+
yield (messages, None)
|
| 182 |
|
| 183 |
final_report = f"# \U0001f9e0 Final Patient Report\n\n{clean_response(stream_text)}"
|
| 184 |
report_path = os.path.join(report_dir, f"report_{datetime.now().strftime('%Y%m%d_%H%M%S')}.md")
|
| 185 |
with open(report_path, 'w') as f:
|
| 186 |
f.write(final_report)
|
| 187 |
|
| 188 |
+
messages.append({"role": "assistant", "content": final_report})
|
| 189 |
+
yield (messages, report_path)
|
| 190 |
|
| 191 |
|
| 192 |
def create_ui(agent):
|
|
|
|
| 217 |
)
|
| 218 |
except Exception as e:
|
| 219 |
print(f"Error: {str(e)}")
|
| 220 |
+
sys.exit(1)
|