Update app.py
Browse files
app.py
CHANGED
@@ -108,15 +108,20 @@ def init_agent():
|
|
108 |
agent.init_model()
|
109 |
return agent
|
110 |
|
111 |
-
def stream_report(agent, file:
|
112 |
accumulated_text = ""
|
113 |
try:
|
114 |
if file is None:
|
115 |
yield "❌ Please upload a valid Excel file.", None, ""
|
116 |
return
|
117 |
|
118 |
-
|
119 |
-
|
|
|
|
|
|
|
|
|
|
|
120 |
chunks = split_text_into_chunks(text)
|
121 |
|
122 |
for i, chunk in enumerate(chunks):
|
@@ -205,7 +210,7 @@ Upload clinical Excel records below and click **Analyze** to generate a medical
|
|
205 |
full_output = gr.State(value="")
|
206 |
|
207 |
analyze_btn.click(
|
208 |
-
fn=stream_report,
|
209 |
inputs=[file_upload, full_output],
|
210 |
outputs=[report_output_markdown, report_file, full_output]
|
211 |
)
|
@@ -216,7 +221,7 @@ if __name__ == "__main__":
|
|
216 |
try:
|
217 |
agent = init_agent()
|
218 |
demo = create_ui(agent)
|
219 |
-
demo.launch(server_name="0.0.0.0", server_port=7860, allowed_paths=["/data/hf_cache/reports"], share=
|
220 |
except Exception as e:
|
221 |
print(f"Error: {str(e)}")
|
222 |
sys.exit(1)
|
|
|
108 |
agent.init_model()
|
109 |
return agent
|
110 |
|
111 |
+
def stream_report(agent, file: Union[str, 'file'], full_output: str) -> Generator:
|
112 |
accumulated_text = ""
|
113 |
try:
|
114 |
if file is None:
|
115 |
yield "❌ Please upload a valid Excel file.", None, ""
|
116 |
return
|
117 |
|
118 |
+
if hasattr(file, "read"):
|
119 |
+
text = extract_text_from_excel(file)
|
120 |
+
elif isinstance(file, str) and os.path.exists(file):
|
121 |
+
text = extract_text_from_excel(file)
|
122 |
+
else:
|
123 |
+
raise ValueError("❌ Invalid or missing file.")
|
124 |
+
|
125 |
chunks = split_text_into_chunks(text)
|
126 |
|
127 |
for i, chunk in enumerate(chunks):
|
|
|
210 |
full_output = gr.State(value="")
|
211 |
|
212 |
analyze_btn.click(
|
213 |
+
fn=lambda file, state: stream_report(agent, file, state),
|
214 |
inputs=[file_upload, full_output],
|
215 |
outputs=[report_output_markdown, report_file, full_output]
|
216 |
)
|
|
|
221 |
try:
|
222 |
agent = init_agent()
|
223 |
demo = create_ui(agent)
|
224 |
+
demo.launch(server_name="0.0.0.0", server_port=7860, allowed_paths=["/data/hf_cache/reports"], share=False)
|
225 |
except Exception as e:
|
226 |
print(f"Error: {str(e)}")
|
227 |
sys.exit(1)
|