Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load your fine-tuned SpanBERT ADR model (replace with your actual model name)
|
| 5 |
+
ner_pipeline = pipeline(
|
| 6 |
+
"token-classification",
|
| 7 |
+
model="hazarri/fine_tuned_spanbert", # make sure this matches your uploaded model repo name
|
| 8 |
+
aggregation_strategy="simple"
|
| 9 |
+
)
|
| 10 |
+
|
| 11 |
+
def extract_adrs(text):
|
| 12 |
+
results = ner_pipeline(text)
|
| 13 |
+
if not results:
|
| 14 |
+
return "No ADR entities found."
|
| 15 |
+
|
| 16 |
+
formatted = []
|
| 17 |
+
for r in results:
|
| 18 |
+
formatted.append(f"{r['word']} ({r['entity_group']}, score={r['score']:.2f})")
|
| 19 |
+
return "\n".join(formatted)
|
| 20 |
+
|
| 21 |
+
demo = gr.Interface(
|
| 22 |
+
fn=extract_adrs,
|
| 23 |
+
inputs=gr.Textbox(lines=5, placeholder="Enter a medical review..."),
|
| 24 |
+
outputs="text",
|
| 25 |
+
title="SpanBERT ADR Extraction API",
|
| 26 |
+
description="Extracts adverse drug reactions (ADRs) from patient reviews using a fine-tuned SpanBERT model."
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
demo.launch()
|