Ali2206 commited on
Commit
9954983
·
verified ·
1 Parent(s): 3dfd69d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -10
app.py CHANGED
@@ -141,8 +141,9 @@ 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 = ""
@@ -163,7 +164,8 @@ Medical Records:
163
  {extracted[:12000]}
164
  ### Potential Oversights:
165
  """
166
- response = ""
 
167
  try:
168
  for chunk in agent.run_gradio_chat(
169
  message=prompt,
@@ -177,15 +179,19 @@ Medical Records:
177
  if chunk is None:
178
  continue
179
  if isinstance(chunk, str):
180
- response += chunk
181
  elif isinstance(chunk, list):
182
- response += "".join([c.content for c in chunk if hasattr(c, 'content') and c.content])
 
 
 
 
183
 
184
- cleaned = response.split("[TOOL_CALLS]")[0].strip()
185
- if not cleaned:
186
- cleaned = "No clear oversights identified. Recommend comprehensive review."
187
 
188
- history[-1] = {"role": "assistant", "content": cleaned}
189
  report_path = os.path.join(report_dir, f"{file_hash_value}_report.txt") if file_hash_value else None
190
  yield history, report_path if report_path and os.path.exists(report_path) else None
191
 
@@ -208,4 +214,4 @@ if __name__ == "__main__":
208
  show_error=True,
209
  allowed_paths=[report_dir],
210
  share=False
211
- )
 
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
+ assistant_msg = {"role": "assistant", "content": "⏳ Analyzing records for potential oversights..."}
146
+ history.append(assistant_msg)
147
  yield history, None
148
 
149
  extracted = ""
 
164
  {extracted[:12000]}
165
  ### Potential Oversights:
166
  """
167
+
168
+ streamed_response = ""
169
  try:
170
  for chunk in agent.run_gradio_chat(
171
  message=prompt,
 
179
  if chunk is None:
180
  continue
181
  if isinstance(chunk, str):
182
+ streamed_response += chunk
183
  elif isinstance(chunk, list):
184
+ streamed_response += "".join([c.content for c in chunk if hasattr(c, 'content')])
185
+
186
+ current_cleaned = streamed_response.split("[TOOL_CALLS]")[0].strip()
187
+ history[-1]["content"] = current_cleaned if current_cleaned else "⏳ Still processing..."
188
+ yield history, None
189
 
190
+ final_cleaned = streamed_response.split("[TOOL_CALLS]")[0].strip()
191
+ if not final_cleaned:
192
+ final_cleaned = "No clear oversights identified. Recommend comprehensive review."
193
 
194
+ history[-1] = {"role": "assistant", "content": final_cleaned}
195
  report_path = os.path.join(report_dir, f"{file_hash_value}_report.txt") if file_hash_value else None
196
  yield history, report_path if report_path and os.path.exists(report_path) else None
197
 
 
214
  show_error=True,
215
  allowed_paths=[report_dir],
216
  share=False
217
+ )