Ali2206 commited on
Commit
9a0b74b
·
verified ·
1 Parent(s): 2e8876b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -119,13 +119,13 @@ def init_agent():
119
  agent.init_model()
120
  return agent
121
 
122
- def process_final_report(agent, file, chatbot_state: List[Dict[str, str]]) -> Tuple[List[Dict[str, str]], Dict[str, Any]]:
123
  messages = chatbot_state if chatbot_state else []
124
- report_output = {"visible": False, "value": None}
125
 
126
  if file is None or not hasattr(file, "name"):
127
  messages.append({"role": "assistant", "content": "❌ Please upload a valid Excel file before analyzing."})
128
- return messages, report_output
129
 
130
  try:
131
  messages.append({"role": "user", "content": f"Processing Excel file: {os.path.basename(file.name)}"})
@@ -193,12 +193,11 @@ def process_final_report(agent, file, chatbot_state: List[Dict[str, str]]) -> Tu
193
  f.write(final_report)
194
 
195
  messages.append({"role": "assistant", "content": f"✅ Report generated and saved: report_{timestamp}.md"})
196
- report_output = {"visible": True, "value": report_path}
197
 
198
  except Exception as e:
199
  messages.append({"role": "assistant", "content": f"❌ Error processing file: {str(e)}"})
200
 
201
- return messages, report_output
202
 
203
  def create_ui(agent):
204
  with gr.Blocks(title="Patient History Chat", css=".gradio-container {max-width: 900px !important}") as demo:
@@ -236,8 +235,9 @@ def create_ui(agent):
236
  chatbot_state = gr.State(value=[])
237
 
238
  def update_ui(file, current_state):
239
- messages, report_output = process_final_report(agent, file, current_state)
240
- return messages, report_output, messages
 
241
 
242
  analyze_btn.click(
243
  fn=update_ui,
 
119
  agent.init_model()
120
  return agent
121
 
122
+ def process_final_report(agent, file, chatbot_state: List[Dict[str, str]]) -> Tuple[List[Dict[str, str]], Union[str, None]]:
123
  messages = chatbot_state if chatbot_state else []
124
+ report_path = None
125
 
126
  if file is None or not hasattr(file, "name"):
127
  messages.append({"role": "assistant", "content": "❌ Please upload a valid Excel file before analyzing."})
128
+ return messages, report_path
129
 
130
  try:
131
  messages.append({"role": "user", "content": f"Processing Excel file: {os.path.basename(file.name)}"})
 
193
  f.write(final_report)
194
 
195
  messages.append({"role": "assistant", "content": f"✅ Report generated and saved: report_{timestamp}.md"})
 
196
 
197
  except Exception as e:
198
  messages.append({"role": "assistant", "content": f"❌ Error processing file: {str(e)}"})
199
 
200
+ return messages, report_path
201
 
202
  def create_ui(agent):
203
  with gr.Blocks(title="Patient History Chat", css=".gradio-container {max-width: 900px !important}") as demo:
 
235
  chatbot_state = gr.State(value=[])
236
 
237
  def update_ui(file, current_state):
238
+ messages, report_path = process_final_report(agent, file, current_state)
239
+ report_update = gr.update(visible=report_path is not None, value=report_path)
240
+ return messages, report_update, messages
241
 
242
  analyze_btn.click(
243
  fn=update_ui,