Ali2206 commited on
Commit
22eb2db
·
verified ·
1 Parent(s): f99effd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -29
app.py CHANGED
@@ -290,7 +290,8 @@ def create_ui(agent):
290
  "assets/user.png",
291
  "assets/assistant.png"
292
  ),
293
- render=False # Disable auto-render for better streaming control
 
294
  )
295
  with gr.Column(scale=1):
296
  final_summary = gr.Markdown(
@@ -332,13 +333,11 @@ def create_ui(agent):
332
 
333
  def update_progress(current, total, stage=""):
334
  progress = f"{stage} - {current}/{total}" if stage else f"{current}/{total}"
335
- return {
336
- progress_text: gr.Textbox(
337
- value=progress,
338
- visible=True,
339
- label=f"Progress: {progress}"
340
- )
341
- }
342
 
343
  prompt_template = """
344
  Analyze the patient record excerpt for missed diagnoses only. Provide a concise, evidence-based summary as a single paragraph without headings or bullet points. Include specific clinical findings (e.g., 'elevated blood pressure (160/95) on page 10'), their potential implications (e.g., 'may indicate untreated hypertension'), and a recommendation for urgent review. Do not include other oversight categories like medication conflicts. If no missed diagnoses are found, state 'No missed diagnoses identified' in a single sentence.
@@ -375,7 +374,7 @@ Patient Record Excerpt (Chunk {0} of {1}):
375
  "chatbot": history,
376
  "download_output": None,
377
  "final_summary": "",
378
- "progress_text": gr.Textbox(visible=True, value="Starting analysis...")
379
  }
380
 
381
  extracted = []
@@ -392,7 +391,9 @@ Patient Record Excerpt (Chunk {0} of {1}):
392
  for i, future in enumerate(as_completed(futures), 1):
393
  try:
394
  extracted.extend(future.result())
395
- yield update_progress(i, len(files), "Processing files")
 
 
396
  except Exception as e:
397
  logger.error(f"File processing error: {e}")
398
  extracted.append({"error": f"Error processing file: {str(e)}"})
@@ -403,7 +404,7 @@ Patient Record Excerpt (Chunk {0} of {1}):
403
  "chatbot": history,
404
  "download_output": None,
405
  "final_summary": "",
406
- "progress_text": gr.Textbox(visible=True, value="Files processed, analyzing content...")
407
  }
408
 
409
  # Convert extracted data to JSON text
@@ -423,10 +424,7 @@ Patient Record Excerpt (Chunk {0} of {1}):
423
  "chatbot": history,
424
  "download_output": None,
425
  "final_summary": "",
426
- "progress_text": gr.Textbox(
427
- visible=True,
428
- value=f"Analyzing chunk {chunk_idx}/{len(chunks)}"
429
- )
430
  }
431
 
432
  # Process and stream the response
@@ -439,10 +437,7 @@ Patient Record Excerpt (Chunk {0} of {1}):
439
  "chatbot": history,
440
  "download_output": None,
441
  "final_summary": "",
442
- "progress_text": gr.Textbox(
443
- visible=True,
444
- value=f"Analyzing chunk {chunk_idx}/{len(chunks)}"
445
- )
446
  }
447
 
448
  combined_response += f"--- Analysis for Chunk {chunk_idx} ---\n{chunk_response}\n"
@@ -462,7 +457,7 @@ Patient Record Excerpt (Chunk {0} of {1}):
462
  "chatbot": history,
463
  "download_output": gr.File(report_path) if report_path and os.path.exists(report_path) else None,
464
  "final_summary": summary,
465
- "progress_text": gr.Textbox(visible=False)
466
  }
467
 
468
  except Exception as e:
@@ -472,18 +467,18 @@ Patient Record Excerpt (Chunk {0} of {1}):
472
  "chatbot": history,
473
  "download_output": None,
474
  "final_summary": f"Error occurred during analysis: {str(e)}",
475
- "progress_text": gr.Textbox(visible=False)
476
  }
477
 
478
  def clear_and_start():
479
- return {
480
- "chatbot": [],
481
- "download_output": None,
482
- "final_summary": "",
483
- "msg_input": "",
484
- "file_upload": None,
485
- "progress_text": gr.Textbox(visible=False)
486
- }
487
 
488
  # Event handlers
489
  send_btn.click(
 
290
  "assets/user.png",
291
  "assets/assistant.png"
292
  ),
293
+ render=False,
294
+ bubble_full_width=False
295
  )
296
  with gr.Column(scale=1):
297
  final_summary = gr.Markdown(
 
333
 
334
  def update_progress(current, total, stage=""):
335
  progress = f"{stage} - {current}/{total}" if stage else f"{current}/{total}"
336
+ return gr.Textbox.update(
337
+ value=progress,
338
+ visible=True,
339
+ label=f"Progress: {progress}"
340
+ )
 
 
341
 
342
  prompt_template = """
343
  Analyze the patient record excerpt for missed diagnoses only. Provide a concise, evidence-based summary as a single paragraph without headings or bullet points. Include specific clinical findings (e.g., 'elevated blood pressure (160/95) on page 10'), their potential implications (e.g., 'may indicate untreated hypertension'), and a recommendation for urgent review. Do not include other oversight categories like medication conflicts. If no missed diagnoses are found, state 'No missed diagnoses identified' in a single sentence.
 
374
  "chatbot": history,
375
  "download_output": None,
376
  "final_summary": "",
377
+ "progress_text": update_progress(0, 1, "Starting")
378
  }
379
 
380
  extracted = []
 
391
  for i, future in enumerate(as_completed(futures), 1):
392
  try:
393
  extracted.extend(future.result())
394
+ yield {
395
+ "progress_text": update_progress(i, len(files), "Processing files")
396
+ }
397
  except Exception as e:
398
  logger.error(f"File processing error: {e}")
399
  extracted.append({"error": f"Error processing file: {str(e)}"})
 
404
  "chatbot": history,
405
  "download_output": None,
406
  "final_summary": "",
407
+ "progress_text": update_progress(len(files), len(files), "Files processed")
408
  }
409
 
410
  # Convert extracted data to JSON text
 
424
  "chatbot": history,
425
  "download_output": None,
426
  "final_summary": "",
427
+ "progress_text": update_progress(chunk_idx, len(chunks), "Analyzing")
 
 
 
428
  }
429
 
430
  # Process and stream the response
 
437
  "chatbot": history,
438
  "download_output": None,
439
  "final_summary": "",
440
+ "progress_text": update_progress(chunk_idx, len(chunks), "Analyzing")
 
 
 
441
  }
442
 
443
  combined_response += f"--- Analysis for Chunk {chunk_idx} ---\n{chunk_response}\n"
 
457
  "chatbot": history,
458
  "download_output": gr.File(report_path) if report_path and os.path.exists(report_path) else None,
459
  "final_summary": summary,
460
+ "progress_text": gr.Textbox.update(visible=False)
461
  }
462
 
463
  except Exception as e:
 
467
  "chatbot": history,
468
  "download_output": None,
469
  "final_summary": f"Error occurred during analysis: {str(e)}",
470
+ "progress_text": gr.Textbox.update(visible=False)
471
  }
472
 
473
  def clear_and_start():
474
+ return [
475
+ [], # chatbot
476
+ None, # download_output
477
+ "", # final_summary
478
+ "", # msg_input
479
+ None, # file_upload
480
+ gr.Textbox.update(visible=False) # progress_text
481
+ ]
482
 
483
  # Event handlers
484
  send_btn.click(