vikramvasudevan commited on
Commit
6fd8766
·
verified ·
1 Parent(s): d76f9b8

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. home.py +34 -21
  2. modules/db.py +10 -1
home.py CHANGED
@@ -294,8 +294,8 @@ def format_final_reports(finals: List[Dict[str, Any]]) -> pd.DataFrame:
294
  {
295
  "final_report_id": str(fr.get("_id", "")),
296
  "generated_at": _fmt(fr.get("generated_at")),
297
- "summary": fr.get("summary", ""),
298
- "recommendations": "; ".join(fr.get("recommendations", [])),
299
  }
300
  )
301
  return pd.DataFrame(
@@ -304,8 +304,8 @@ def format_final_reports(finals: List[Dict[str, Any]]) -> pd.DataFrame:
304
  {
305
  "final_report_id": "",
306
  "generated_at": "",
307
- "summary": "",
308
- "recommendations": "",
309
  }
310
  ]
311
  )
@@ -465,8 +465,8 @@ with gr.Blocks(
465
  headers=[
466
  "final_report_id",
467
  "generated_at",
468
- "summary",
469
- "recommendations",
470
  ],
471
  row_count=(0, "dynamic"),
472
  wrap=True,
@@ -474,18 +474,20 @@ with gr.Blocks(
474
  )
475
 
476
  with Modal(visible=False) as final_report_download_modal:
477
- gr.Markdown("# download report")
478
  with gr.Row():
 
479
  report_id_in = gr.Textbox(
480
  label="Report ID",
481
  placeholder="Paste Report ID to download",
 
482
  )
483
- download_btn = gr.Button(
484
- "⬇️ Download PDF", variant="primary"
485
- )
486
- download_file = gr.File(
487
- label="Your PDF", type="binary", file_types=[".pdf"], file_count="single"
488
  )
 
 
 
489
 
490
  # Function triggered when a row is selected
491
  def on_row_select(df_row):
@@ -493,23 +495,34 @@ with gr.Blocks(
493
  if df_row is None:
494
  return gr.update(visible=False), None
495
  report_id = df_row["final_report_id"][0]
 
 
496
  # Return modal visibility + the file to bind to download button
497
- return gr.update(visible=True), str(report_id)
 
 
 
 
 
498
 
499
  final_df.select(close_side_bar, outputs=[sheami_sidebar]).then(
500
  on_row_select,
501
  inputs=[final_df],
502
- outputs=[final_report_download_modal, report_id_in],
 
 
 
 
 
503
  )
504
  download_btn.click(
505
- fn=download_final_report,
506
- inputs=[report_id_in],
507
- outputs=download_file
508
- )
509
 
510
- gr.Markdown("Tip: Select another patient to refresh final reports.")
511
  with gr.Tab("📄 Upload History"):
512
- gr.Markdown("## here is your upload history")
513
 
514
  # ---- Events ----
515
  def on_load(email):
@@ -531,7 +544,7 @@ with gr.Blocks(
531
  selected_patient_info,
532
  reports_df_val,
533
  gr.update(choices=test_names),
534
- format_final_reports(finals),
535
  )
536
 
537
  patient_list.change(
 
294
  {
295
  "final_report_id": str(fr.get("_id", "")),
296
  "generated_at": _fmt(fr.get("generated_at")),
297
+ # "summary": fr.get("summary", ""),
298
+ # "recommendations": "; ".join(fr.get("recommendations", [])),
299
  }
300
  )
301
  return pd.DataFrame(
 
304
  {
305
  "final_report_id": "",
306
  "generated_at": "",
307
+ # "summary": "",
308
+ # "recommendations": "",
309
  }
310
  ]
311
  )
 
465
  headers=[
466
  "final_report_id",
467
  "generated_at",
468
+ # "summary",
469
+ # "recommendations",
470
  ],
471
  row_count=(0, "dynamic"),
472
  wrap=True,
 
474
  )
475
 
476
  with Modal(visible=False) as final_report_download_modal:
 
477
  with gr.Row():
478
+ gr.Column()
479
  report_id_in = gr.Textbox(
480
  label="Report ID",
481
  placeholder="Paste Report ID to download",
482
+ visible=False,
483
  )
484
+
485
+ download_btn = gr.DownloadButton(
486
+ "⬇️ Download PDF", variant="primary", scale=0
 
 
487
  )
488
+ gr.Column()
489
+
490
+ html_report_component = gr.HTML()
491
 
492
  # Function triggered when a row is selected
493
  def on_row_select(df_row):
 
495
  if df_row is None:
496
  return gr.update(visible=False), None
497
  report_id = df_row["final_report_id"][0]
498
+ report_file_name = download_final_report(report_id)
499
+ report_html_content = get_db().get_final_report_html(report_id)
500
  # Return modal visibility + the file to bind to download button
501
+ return (
502
+ gr.update(visible=True),
503
+ str(report_id),
504
+ report_file_name,
505
+ report_html_content,
506
+ ) # final_report_download_modal, report_id_in, download_btn, html_report
507
 
508
  final_df.select(close_side_bar, outputs=[sheami_sidebar]).then(
509
  on_row_select,
510
  inputs=[final_df],
511
+ outputs=[
512
+ final_report_download_modal,
513
+ report_id_in,
514
+ download_btn,
515
+ html_report_component,
516
+ ],
517
  )
518
  download_btn.click(
519
+ fn=download_final_report,
520
+ inputs=[report_id_in],
521
+ outputs=download_btn,
522
+ )
523
 
 
524
  with gr.Tab("📄 Upload History"):
525
+ gr.Markdown("### here is your upload history")
526
 
527
  # ---- Events ----
528
  def on_load(email):
 
544
  selected_patient_info,
545
  reports_df_val,
546
  gr.update(choices=test_names),
547
+ gr.update(headers=["final_report_id","generated_at"],value=format_final_reports(finals)),
548
  )
549
 
550
  patient_list.change(
modules/db.py CHANGED
@@ -435,4 +435,13 @@ class SheamiDB:
435
  doc = self.final_reports.find_one({"_id": ObjectId(report_id)})
436
  if not doc or not doc.get("pdf_file_id"):
437
  return None
438
- return self.fs.get(doc["pdf_file_id"]).read()
 
 
 
 
 
 
 
 
 
 
435
  doc = self.final_reports.find_one({"_id": ObjectId(report_id)})
436
  if not doc or not doc.get("pdf_file_id"):
437
  return None
438
+ return self.fs.get(doc["pdf_file_id"]).read()
439
+
440
+ def get_final_report_html(self, report_id: str) -> bytes | None:
441
+ """
442
+ Fetch the HTML for a given final_report (if stored).
443
+ """
444
+ doc = self.final_reports.find_one({"_id": ObjectId(report_id)})
445
+ if not doc or not doc.get("summary"):
446
+ return "<html></html>"#empty tag
447
+ return doc.get("summary")