Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import PegasusForConditionalGeneration,PegasusTokenizer
|
2 |
+
import gradio as grad
|
3 |
+
|
4 |
+
|
5 |
+
|
6 |
+
mdl_name = "google/pegasus-xsum"
|
7 |
+
|
8 |
+
pegasus_tkn = PegasusTokenizer.from_pretrained(mdl_name)
|
9 |
+
|
10 |
+
mdl = PegasusForConditionalGeneration.from_pretrained(mdl_name)
|
11 |
+
|
12 |
+
|
13 |
+
|
14 |
+
def summarize(text):
|
15 |
+
|
16 |
+
tokens = pegasus_tkn(text,
|
17 |
+
truncation = True,
|
18 |
+
padding="longest",
|
19 |
+
return_tensors="pt")
|
20 |
+
|
21 |
+
txt_summary = mdl.generate(**tokens)
|
22 |
+
|
23 |
+
response = pegasus_tkn.batch_decode(txt_summary,
|
24 |
+
skip_special_tokens=True)
|
25 |
+
|
26 |
+
return response
|
27 |
+
|
28 |
+
|
29 |
+
txt = grad.Textbox(lines = 10,
|
30 |
+
label = "English",
|
31 |
+
placeholder = "English Text here")
|
32 |
+
|
33 |
+
out = grad.Textbox(lines = 10,
|
34 |
+
label = "Summary")
|
35 |
+
|
36 |
+
grad.Interface(summarize,
|
37 |
+
inputs = txt,
|
38 |
+
outputs = out).launch()
|