Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoTokenizer, AutoModelWithMLHead
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
model_name = "deep-learning-analytics/wikihow-t5-small"
|
5 |
+
model = AutoModelWithMLHead.from_pretrained(model_name)
|
6 |
+
text2text_tokenizer = AutoTokenizer.from_pretrained(model_name)
|
7 |
+
|
8 |
+
def text2text(paragraph):
|
9 |
+
text = paragraph.strip().replace("\n", "")
|
10 |
+
token_text = text2text_tokenizer.encode(text, return_tensors="pt")
|
11 |
+
token_ids = model.generate(token_text, max_length=250, num_beams=5, repetition_penality=2.5, early_stopping=True)
|
12 |
+
response = text2text_tokenizer.decode(token_ids[0], skip_special_tokens=True)
|
13 |
+
return response
|
14 |
+
|
15 |
+
in_para = gr.Textbox(lines=10, label="Paragraph", placeholder="Copy paragraph")
|
16 |
+
out = gr.Textbox(lines=1, label="Summary")
|
17 |
+
gr.Interface(text2text, inputs=in_para, outputs=out)
|