Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,16 +1,44 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
3 |
|
4 |
-
|
5 |
-
|
|
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
output = model.generate(inputs["input_ids"])
|
10 |
-
summary = tokenizer.decode(output[0], skip_special_tokens=True)
|
11 |
-
return summary
|
12 |
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
if __name__ == "__main__":
|
16 |
iface.launch(share=False)
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
3 |
|
4 |
+
model_checkpoint = "Mbilal755/Radiology_Bart"
|
5 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_checkpoint)
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)
|
7 |
|
8 |
+
from transformers import SummarizationPipeline
|
9 |
+
summarizer = SummarizationPipeline(model=model, tokenizer=tokenizer)
|
|
|
|
|
|
|
10 |
|
11 |
+
import gradio as gr
|
12 |
+
|
13 |
+
examples = [
|
14 |
+
"prevoid bladder volume cc postvoid bladder volume cc bladder grossly normal appearance",
|
15 |
+
"heart mediastinal contours normal left sided subclavian line position tip distal svc lungs remain clear active disease effusions",
|
16 |
+
"""
|
17 |
+
heart size normal mediastinal hilar contours remain stable small right pneumothorax remains unchanged surgical lung staples overlying
|
18 |
+
left upper lobe seen linear pattern consistent prior upper lobe resection soft tissue osseous structures appear unremarkable nasogastric
|
19 |
+
endotracheal tubes remain satisfactory position atelectatic changes right lower lung field remain unchanged prior study
|
20 |
+
"""
|
21 |
+
]
|
22 |
+
|
23 |
+
description = """
|
24 |
+
We fine-tuned the BioBart 440M parameter model on a dataset of 52,000 radiology reports scraped from MIMIC-III specifically for the task of summarization.
|
25 |
+
|
26 |
+
The model is able to generate impressions summarizing key findings from the longer radiology reports.
|
27 |
+
|
28 |
+
Enter a radiology report to see the generated impression summary!
|
29 |
+
"""
|
30 |
+
|
31 |
+
def summarize(radiology_report):
|
32 |
+
summary = summarizer(radiology_report)[0]['summary_text']
|
33 |
+
return summary
|
34 |
|
35 |
+
iface = gr.Interface(fn=summarize,
|
36 |
+
inputs=gr.inputs.Textbox(lines=5, label="Radiology Report"),
|
37 |
+
outputs=gr.outputs.Textbox(label="Summary"),
|
38 |
+
examples=examples,
|
39 |
+
title="Radiology Report Summarization",
|
40 |
+
description=description,
|
41 |
+
theme="huggingface")
|
42 |
+
|
43 |
if __name__ == "__main__":
|
44 |
iface.launch(share=False)
|