Spaces:
Sleeping
Sleeping
shandong1970
commited on
Commit
•
16386f3
1
Parent(s):
d87e57e
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoTokenizer, AutoModelWithLMHead
|
2 |
+
import gradio as grad
|
3 |
+
text2text_tkn = AutoTokenizer.from_pretrained("deep-learning-analytics/wikihow-t5-small")
|
4 |
+
mdl = AutoModelWithLMHead.from_pretrained("deep-learning-analytics/wikihow-t5-small")
|
5 |
+
|
6 |
+
def text2text_summary(para):
|
7 |
+
initial_txt = para.strip().replace("\n","")
|
8 |
+
tkn_text = text2text_tkn.encode(initial_txt,return_tensors="pt")
|
9 |
+
|
10 |
+
tkn_ids = mdl.generate(tkn_text,max_length=250,num_beams=5,repetition_penalty=2.5, early_stopping=True)
|
11 |
+
response = text2text_tkn.decode(tkn_ids[0],skip_special_tokens=True)
|
12 |
+
return response
|
13 |
+
|
14 |
+
para = grad.Textbox(lines=10, label="Paragraph",placeholder="Copy paragraph")
|
15 |
+
out = grad.Textbox(lines=1, label="Summary")
|
16 |
+
grad.Interface(text2text_summary, inputs=para, outputs=out).launch()
|