Ali2206 commited on
Commit
f99effd
·
verified ·
1 Parent(s): 8547f5e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -23
app.py CHANGED
@@ -285,12 +285,12 @@ def create_ui(agent):
285
  chatbot = gr.Chatbot(
286
  label="Analysis Conversation",
287
  height=600,
288
- bubble_full_width=False,
289
  show_copy_button=True,
290
  avatar_images=(
291
  "assets/user.png",
292
  "assets/assistant.png"
293
- )
 
294
  )
295
  with gr.Column(scale=1):
296
  final_summary = gr.Markdown(
@@ -324,11 +324,22 @@ def create_ui(agent):
324
  min_width=100
325
  )
326
 
327
- progress_bar = gr.Progress(
328
- label="Processing Progress",
329
- visible=False
 
330
  )
331
 
 
 
 
 
 
 
 
 
 
 
332
  prompt_template = """
333
  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.
334
  Patient Record Excerpt (Chunk {0} of {1}):
@@ -364,7 +375,7 @@ Patient Record Excerpt (Chunk {0} of {1}):
364
  "chatbot": history,
365
  "download_output": None,
366
  "final_summary": "",
367
- "progress_bar": gr.Progress(visible=True)
368
  }
369
 
370
  extracted = []
@@ -378,9 +389,10 @@ Patient Record Excerpt (Chunk {0} of {1}):
378
  file_type = f.name.split(".")[-1].lower()
379
  futures.append(executor.submit(process_file, f.name, file_type))
380
 
381
- for future in as_completed(futures):
382
  try:
383
  extracted.extend(future.result())
 
384
  except Exception as e:
385
  logger.error(f"File processing error: {e}")
386
  extracted.append({"error": f"Error processing file: {str(e)}"})
@@ -391,7 +403,7 @@ Patient Record Excerpt (Chunk {0} of {1}):
391
  "chatbot": history,
392
  "download_output": None,
393
  "final_summary": "",
394
- "progress_bar": gr.Progress(0.2, visible=True, label="Processing files")
395
  }
396
 
397
  # Convert extracted data to JSON text
@@ -411,10 +423,9 @@ Patient Record Excerpt (Chunk {0} of {1}):
411
  "chatbot": history,
412
  "download_output": None,
413
  "final_summary": "",
414
- "progress_bar": gr.Progress(
415
- 0.2 + (chunk_idx/len(chunks))*0.7,
416
- visible=True,
417
- label=f"Analyzing chunk {chunk_idx}/{len(chunks)}"
418
  )
419
  }
420
 
@@ -428,9 +439,9 @@ Patient Record Excerpt (Chunk {0} of {1}):
428
  "chatbot": history,
429
  "download_output": None,
430
  "final_summary": "",
431
- "progress_bar": gr.Progress(
432
- 0.2 + (chunk_idx/len(chunks))*0.7,
433
- visible=True
434
  )
435
  }
436
 
@@ -451,7 +462,7 @@ Patient Record Excerpt (Chunk {0} of {1}):
451
  "chatbot": history,
452
  "download_output": gr.File(report_path) if report_path and os.path.exists(report_path) else None,
453
  "final_summary": summary,
454
- "progress_bar": gr.Progress(1.0, visible=False)
455
  }
456
 
457
  except Exception as e:
@@ -461,7 +472,7 @@ Patient Record Excerpt (Chunk {0} of {1}):
461
  "chatbot": history,
462
  "download_output": None,
463
  "final_summary": f"Error occurred during analysis: {str(e)}",
464
- "progress_bar": gr.Progress(visible=False)
465
  }
466
 
467
  def clear_and_start():
@@ -470,27 +481,28 @@ Patient Record Excerpt (Chunk {0} of {1}):
470
  "download_output": None,
471
  "final_summary": "",
472
  "msg_input": "",
473
- "file_upload": None
 
474
  }
475
 
476
  # Event handlers
477
  send_btn.click(
478
  analyze,
479
  inputs=[msg_input, chatbot, file_upload],
480
- outputs=[chatbot, download_output, final_summary, progress_bar],
481
  show_progress="hidden"
482
  )
483
 
484
  msg_input.submit(
485
  analyze,
486
  inputs=[msg_input, chatbot, file_upload],
487
- outputs=[chatbot, download_output, final_summary, progress_bar],
488
  show_progress="hidden"
489
  )
490
 
491
  demo.load(
492
  clear_and_start,
493
- outputs=[chatbot, download_output, final_summary, msg_input, file_upload],
494
  queue=False
495
  )
496
 
@@ -509,8 +521,7 @@ if __name__ == "__main__":
509
  server_port=7860,
510
  show_error=True,
511
  allowed_paths=[report_dir],
512
- share=False,
513
- favicon_path="assets/favicon.ico"
514
  )
515
  except Exception as e:
516
  logger.error(f"Failed to launch app: {e}")
 
285
  chatbot = gr.Chatbot(
286
  label="Analysis Conversation",
287
  height=600,
 
288
  show_copy_button=True,
289
  avatar_images=(
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(
 
324
  min_width=100
325
  )
326
 
327
+ progress_text = gr.Textbox(
328
+ label="Progress",
329
+ visible=False,
330
+ interactive=False
331
  )
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.
345
  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 = []
 
389
  file_type = f.name.split(".")[-1].lower()
390
  futures.append(executor.submit(process_file, f.name, file_type))
391
 
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
  "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
  "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
 
 
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
 
 
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
  "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():
 
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(
490
  analyze,
491
  inputs=[msg_input, chatbot, file_upload],
492
+ outputs=[chatbot, download_output, final_summary, progress_text],
493
  show_progress="hidden"
494
  )
495
 
496
  msg_input.submit(
497
  analyze,
498
  inputs=[msg_input, chatbot, file_upload],
499
+ outputs=[chatbot, download_output, final_summary, progress_text],
500
  show_progress="hidden"
501
  )
502
 
503
  demo.load(
504
  clear_and_start,
505
+ outputs=[chatbot, download_output, final_summary, msg_input, file_upload, progress_text],
506
  queue=False
507
  )
508
 
 
521
  server_port=7860,
522
  show_error=True,
523
  allowed_paths=[report_dir],
524
+ share=False
 
525
  )
526
  except Exception as e:
527
  logger.error(f"Failed to launch app: {e}")