diogo.rodrigues.silva commited on
Commit
3fa9493
·
1 Parent(s): af5dc19

update app.py

Browse files
Files changed (2) hide show
  1. __pycache__/app.cpython-310.pyc +0 -0
  2. app.py +42 -8
__pycache__/app.cpython-310.pyc DELETED
Binary file (13.7 kB)
 
app.py CHANGED
@@ -18,6 +18,7 @@ from tempfile import mkdtemp
18
  from urllib.parse import quote
19
 
20
  import gradio as gr
 
21
  import uvicorn
22
  from fastapi import Depends, FastAPI, HTTPException, Query, status
23
  from fastapi.responses import FileResponse
@@ -135,6 +136,26 @@ def _download_markdown(file_path: Path, label: str) -> str:
135
  return f"[{label}]({_download_href(file_path)})"
136
 
137
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
138
  def _auth_credentials() -> tuple[str, str]:
139
  username = (os.getenv(APP_USERNAME_ENV) or "").strip()
140
  password = (os.getenv(APP_PASSWORD_ENV) or "").strip()
@@ -338,8 +359,19 @@ def screen_excel(
338
  return
339
 
340
  progress(1, desc="Screening complete.")
 
 
 
 
 
 
 
 
 
 
 
341
  yield (
342
- f"Screening complete: {screened_output.name}",
343
  _download_markdown(screened_output, "Download Screened Excel"),
344
  )
345
 
@@ -353,9 +385,9 @@ def build_app() -> gr.Blocks:
353
  )
354
 
355
  with gr.Blocks(title="Reference Parser + Foundry Screener") as demo:
356
- gr.Markdown("# Reference Parser and Screener")
357
  gr.Markdown(
358
- "Upload `.txt/.medline/.ris` files, parse into one Excel, then screen with Azure Foundry using Space secrets."
359
  )
360
  gr.Markdown(f"**Secrets status:** {secrets_note}")
361
 
@@ -386,15 +418,17 @@ def build_app() -> gr.Blocks:
386
  )
387
  criteria_inclusion_text = gr.Textbox(
388
  label="Inclusion Criteria (one per line)",
389
- lines=4,
390
  )
391
  criteria_exclusion_text = gr.Textbox(
392
  label="Exclusion Criteria (one per line)",
393
- lines=4,
394
  )
395
- criteria_notes = gr.Textbox(label="Notes (optional)", lines=2)
396
- title_column = gr.Textbox(label="Title Column", value="Title")
397
- abstract_column = gr.Textbox(label="Abstract Column", value="Abstract")
 
 
398
 
399
  parse_btn.click(
400
  fn=parse_files,
 
18
  from urllib.parse import quote
19
 
20
  import gradio as gr
21
+ import pandas as pd
22
  import uvicorn
23
  from fastapi import Depends, FastAPI, HTTPException, Query, status
24
  from fastapi.responses import FileResponse
 
136
  return f"[{label}]({_download_href(file_path)})"
137
 
138
 
139
+ def _screening_verdict_counts(screened_excel_path: Path) -> dict[str, int]:
140
+ df = pd.read_excel(screened_excel_path, engine="openpyxl")
141
+ if "LLM_verdict" not in df.columns:
142
+ raise KeyError("Expected 'LLM_verdict' column was not found in screening output.")
143
+
144
+ verdict_counts = (
145
+ df["LLM_verdict"]
146
+ .astype(str)
147
+ .str.strip()
148
+ .str.lower()
149
+ .value_counts()
150
+ .to_dict()
151
+ )
152
+ return {
153
+ "include": int(verdict_counts.get("include", 0)),
154
+ "exclude": int(verdict_counts.get("exclude", 0)),
155
+ "unclear": int(verdict_counts.get("unclear", 0)),
156
+ }
157
+
158
+
159
  def _auth_credentials() -> tuple[str, str]:
160
  username = (os.getenv(APP_USERNAME_ENV) or "").strip()
161
  password = (os.getenv(APP_PASSWORD_ENV) or "").strip()
 
359
  return
360
 
361
  progress(1, desc="Screening complete.")
362
+ try:
363
+ verdict_counts = _screening_verdict_counts(screened_output)
364
+ completed_status = (
365
+ "Screening complete: "
366
+ f"Included {verdict_counts['include']} | "
367
+ f"Excluded {verdict_counts['exclude']} | "
368
+ f"Unclear {verdict_counts['unclear']}"
369
+ )
370
+ except Exception:
371
+ completed_status = "Screening complete."
372
+
373
  yield (
374
+ completed_status,
375
  _download_markdown(screened_output, "Download Screened Excel"),
376
  )
377
 
 
385
  )
386
 
387
  with gr.Blocks(title="Reference Parser + Foundry Screener") as demo:
388
+ gr.Markdown("# Reference Parsing, Deduplication and LLM-assisted Screening")
389
  gr.Markdown(
390
+ "Upload `.txt/.medline/.ris` files, parse into one Excel, then screen for inclusion/exclusion criteria."
391
  )
392
  gr.Markdown(f"**Secrets status:** {secrets_note}")
393
 
 
418
  )
419
  criteria_inclusion_text = gr.Textbox(
420
  label="Inclusion Criteria (one per line)",
421
+ lines=2,
422
  )
423
  criteria_exclusion_text = gr.Textbox(
424
  label="Exclusion Criteria (one per line)",
425
+ lines=2,
426
  )
427
+ criteria_notes = gr.Textbox(label="Notes (optional)", lines=1)
428
+ # title_column = gr.Textbox(label="Title Column", value="Title")
429
+ # abstract_column = gr.Textbox(label="Abstract Column", value="Abstract")
430
+ title_column = "Title"
431
+ abstract_column = "Abstract"
432
 
433
  parse_btn.click(
434
  fn=parse_files,