Upload 2 files
Browse files- app.py +17 -0
- requirements.txt +4 -0
app.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import PegasusForConditionalGeneration, PegasusTokenizer
|
| 2 |
+
import gradio as grad
|
| 3 |
+
mdl_name = "google/pegasus-xsum"
|
| 4 |
+
pegasus_tkn = PegasusTokenizer.from_pretrained(mdl_name)
|
| 5 |
+
mdl = PegasusForConditionalGeneration.from_pretrained(mdl_name)
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def summarize(text):
|
| 11 |
+
tokens = pegasus_tkn(text, truncation=True, padding="longest", return_tensors="pt")
|
| 12 |
+
txt_summary = mdl.generate(**tokens)
|
| 13 |
+
response = pegasus_tkn.batch_decode(txt_summary, skip_special_tokens=True)
|
| 14 |
+
return response
|
| 15 |
+
txt=grad.Textbox(lines=10, label="English", placeholder="English Text here")
|
| 16 |
+
out=grad.Textbox(lines=10, label="Summary")
|
| 17 |
+
grad.Interface(summarize, inputs=txt, outputs=out).launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
transformers
|
| 3 |
+
torch
|
| 4 |
+
transformers[sentencepiece]
|