Ali2206 commited on
Commit
fd2b3df
·
verified ·
1 Parent(s): 6cafd98

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -14
app.py CHANGED
@@ -141,8 +141,8 @@ def create_ui(agent):
141
  download_output = gr.File(label="Download Full Report")
142
 
143
  def analyze(message: str, history: list, files: list):
144
- history = history + [{"role": "user", "content": message},
145
- {"role": "assistant", "content": "⏳ Analyzing records for potential oversights..."}]
146
  yield history, None
147
 
148
  extracted = ""
@@ -165,8 +165,9 @@ Medical Records:
165
 
166
  ### Potential Oversights:
167
  """
168
- response = ""
169
  try:
 
170
  for chunk in agent.run_gradio_chat(
171
  message=prompt,
172
  history=[],
@@ -174,26 +175,24 @@ Medical Records:
174
  max_new_tokens=2048,
175
  max_token=4096,
176
  call_agent=False,
177
- conversation=[],
178
  ):
179
- if chunk is None:
180
- continue
181
  if isinstance(chunk, str):
182
  response += chunk
183
  elif isinstance(chunk, list):
184
- response += "".join([c.content for c in chunk if hasattr(c, 'content') and c.content])
185
 
186
- cleaned = response.split("[TOOL_CALLS]")[0].strip()
187
- if not cleaned:
188
- cleaned = "No clear oversights identified. Recommend comprehensive review."
189
 
190
- history[-1] = {"role": "assistant", "content": cleaned}
191
  report_path = os.path.join(report_dir, f"{file_hash_value}_report.txt") if file_hash_value else None
192
  yield history, report_path if report_path and os.path.exists(report_path) else None
193
 
194
  except Exception as e:
195
- print("🚨 ERROR:", e)
196
- history[-1] = {"role": "assistant", "content": f"❌ Error occurred: {str(e)}"}
197
  yield history, None
198
 
199
  send_btn.click(analyze, inputs=[msg_input, gr.State([]), file_upload], outputs=[chatbot, download_output])
@@ -210,4 +209,4 @@ if __name__ == "__main__":
210
  show_error=True,
211
  allowed_paths=[report_dir],
212
  share=False
213
- )
 
141
  download_output = gr.File(label="Download Full Report")
142
 
143
  def analyze(message: str, history: list, files: list):
144
+ history.append({"role": "user", "content": message})
145
+ history.append({"role": "assistant", "content": "⏳ Analyzing records for potential oversights..."})
146
  yield history, None
147
 
148
  extracted = ""
 
165
 
166
  ### Potential Oversights:
167
  """
168
+
169
  try:
170
+ response = ""
171
  for chunk in agent.run_gradio_chat(
172
  message=prompt,
173
  history=[],
 
175
  max_new_tokens=2048,
176
  max_token=4096,
177
  call_agent=False,
178
+ conversation=[]
179
  ):
 
 
180
  if isinstance(chunk, str):
181
  response += chunk
182
  elif isinstance(chunk, list):
183
+ response += "".join([c.content for c in chunk if hasattr(c, "content") and c.content])
184
 
185
+ clean_response = response.split("[TOOL_CALLS]")[0].strip()
186
+ if not clean_response:
187
+ clean_response = "⚠️ No clear oversights identified or an error occurred."
188
 
189
+ history[-1] = {"role": "assistant", "content": clean_response}
190
  report_path = os.path.join(report_dir, f"{file_hash_value}_report.txt") if file_hash_value else None
191
  yield history, report_path if report_path and os.path.exists(report_path) else None
192
 
193
  except Exception as e:
194
+ print("ERROR:", str(e))
195
+ history[-1] = {"role": "assistant", "content": f"❌ An 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])
 
209
  show_error=True,
210
  allowed_paths=[report_dir],
211
  share=False
212
+ )