Spaces:
Runtime error
Runtime error
Commit
Β·
8eb9b76
1
Parent(s):
07b5688
Initial commit - PICO extractor with GLiNER
Browse files- .gitignore +4 -0
- README.md +30 -10
- app.py +57 -0
- requirements.txt +4 -0
.gitignore
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
venv/
|
| 2 |
+
__pycache__/
|
| 3 |
+
*.pyc
|
| 4 |
+
.env
|
README.md
CHANGED
|
@@ -1,12 +1,32 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
---
|
| 11 |
|
| 12 |
-
|
|
|
|
| 1 |
+
# GLiNER-BioMed PICO Extractor
|
| 2 |
+
|
| 3 |
+
This Hugging Face Space extracts PICO elements (Population, Intervention, Comparison, Outcome) from:
|
| 4 |
+
|
| 5 |
+
- Raw biomedical abstracts
|
| 6 |
+
- `.nbib` reference files
|
| 7 |
+
|
| 8 |
+
### Model
|
| 9 |
+
|
| 10 |
+
Powered by `Ihor/gliner-biomed-bi-small-v1.0` β a compact BERT-like NER model trained for biomedical text using synthetic annotations.
|
| 11 |
+
|
| 12 |
+
### Features
|
| 13 |
+
|
| 14 |
+
- β
Zero-shot extraction using natural language entity descriptions
|
| 15 |
+
- π NBIB parser for PubMed export files
|
| 16 |
+
- β‘ Lightweight: deploys on CPU-only Spaces
|
| 17 |
+
|
| 18 |
+
### How to Use
|
| 19 |
+
|
| 20 |
+
1. **Paste a biomedical abstract** in the textbox β Get labeled PICO entities.
|
| 21 |
+
2. **Upload a `.nbib` file** β Get per-abstract PICO extractions.
|
| 22 |
+
|
| 23 |
+
### Dependencies
|
| 24 |
+
|
| 25 |
+
- `gradio`
|
| 26 |
+
- `gliner`
|
| 27 |
+
- `torch`
|
| 28 |
+
- `transformers`
|
| 29 |
+
|
| 30 |
---
|
| 31 |
|
| 32 |
+
Inspired by the needs of evidence-based medicine and large-scale systematic reviews.
|
app.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from gliner import GLiNER
|
| 4 |
+
import re
|
| 5 |
+
|
| 6 |
+
# Load GLiNER-BioMed Small model
|
| 7 |
+
model = GLiNER.from_pretrained("Ihor/gliner-biomed-bi-small-v1.0")
|
| 8 |
+
labels = ["Population", "Intervention", "Comparison", "Outcome"]
|
| 9 |
+
|
| 10 |
+
def parse_nbib(file):
|
| 11 |
+
content = file.read().decode("utf-8")
|
| 12 |
+
entries = re.findall(r'(?=PMID- .+?)(.*?)(?=(?:PMID- |\Z))', content, re.DOTALL)
|
| 13 |
+
refs = []
|
| 14 |
+
for entry in entries:
|
| 15 |
+
title = ""
|
| 16 |
+
abstract = ""
|
| 17 |
+
for line in entry.splitlines():
|
| 18 |
+
if line.startswith("TI - "):
|
| 19 |
+
title = line.replace("TI - ", "").strip()
|
| 20 |
+
elif line.startswith("AB - "):
|
| 21 |
+
abstract += " " + line.replace("AB - ", "").strip()
|
| 22 |
+
if title or abstract:
|
| 23 |
+
refs.append(f"{title}. {abstract.strip()}")
|
| 24 |
+
return refs
|
| 25 |
+
|
| 26 |
+
def extract_pico_from_nbib(file):
|
| 27 |
+
refs = parse_nbib(file)
|
| 28 |
+
results = []
|
| 29 |
+
for ref in refs:
|
| 30 |
+
entities = model.predict_entities(ref, labels, threshold=0.5)
|
| 31 |
+
results.append({"text": ref, "pico": entities})
|
| 32 |
+
return results
|
| 33 |
+
|
| 34 |
+
def extract_from_text(text):
|
| 35 |
+
entities = model.predict_entities(text, labels, threshold=0.5)
|
| 36 |
+
return {ent['label']: ent['text'] for ent in entities}
|
| 37 |
+
|
| 38 |
+
demo = gr.Interface(
|
| 39 |
+
fn=extract_from_text,
|
| 40 |
+
inputs=gr.Textbox(lines=10, placeholder="Paste biomedical abstract here..."),
|
| 41 |
+
outputs="json",
|
| 42 |
+
title="PICO Extractor (GLiNER-BioMed Small)",
|
| 43 |
+
description="Extract PICO (Population, Intervention, Comparison, Outcome) elements from biomedical text using the GLiNER-BioMed Small model."
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
nbib_demo = gr.Interface(
|
| 47 |
+
fn=extract_pico_from_nbib,
|
| 48 |
+
inputs=gr.File(file_types=[".nbib"]),
|
| 49 |
+
outputs="json",
|
| 50 |
+
title="PICO Extractor from NBIB",
|
| 51 |
+
description="Upload .nbib files to extract PICO elements using GLiNER-BioMed Small."
|
| 52 |
+
)
|
| 53 |
+
|
| 54 |
+
tabs = gr.TabbedInterface([demo, nbib_demo], ["From Text", "From NBIB File"])
|
| 55 |
+
|
| 56 |
+
if __name__ == "__main__":
|
| 57 |
+
tabs.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio>=4.0.0
|
| 2 |
+
gliner==0.2.0
|
| 3 |
+
torch>=1.10
|
| 4 |
+
transformers
|