Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
+
from huggingface_hub import hf_hub_download
|
| 4 |
+
|
| 5 |
+
model_path = hf_hub_download(repo_id="Mbilal755/Radiology_Bart", filename="pytorch_model.bin")
|
| 6 |
+
model = torch.load(model_path)
|
| 7 |
+
|
| 8 |
+
# Load tokenizer
|
| 9 |
+
tokenizer = hf_hub_download(repo_id="Mbilal755/Radiology_Bart", filename="tokenizer.json")
|
| 10 |
+
tokenizer = tokenizer.tokenizer
|
| 11 |
+
|
| 12 |
+
def summarize(text):
|
| 13 |
+
inputs = tokenizer(text, return_tensors="pt")
|
| 14 |
+
summary_ids = model.generate(inputs["input_ids"])
|
| 15 |
+
summary = tokenizer.decode(summary_ids[0])
|
| 16 |
+
return summary
|
| 17 |
+
|
| 18 |
+
iface = gr.Interface(fn=summarize, inputs="text", outputs="text")
|
| 19 |
+
|
| 20 |
+
if __name__ == "__main__":
|
| 21 |
+
iface.launch(share=True)
|