Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,17 +1,26 @@
|
|
1 |
-
from transformers import AutoTokenizer,
|
2 |
import gradio as gr
|
3 |
|
4 |
model_name = "deep-learning-analytics/wikihow-t5-small"
|
5 |
-
|
6 |
-
|
7 |
|
8 |
-
def
|
9 |
-
|
10 |
-
token_text =
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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(
|
|
|
1 |
+
from transformers import AutoTokenizer, AutoModelWithLMHead
|
2 |
import gradio as gr
|
3 |
|
4 |
model_name = "deep-learning-analytics/wikihow-t5-small"
|
5 |
+
text2text_token = AutoTokenizer.from_pretrained(model_name)
|
6 |
+
model = AutoModelWithLMHead.from_pretrained(model_name)
|
7 |
|
8 |
+
def text2text_summary(para):
|
9 |
+
initial_text = para.strip().replace("\n","")
|
10 |
+
token_text = text2text_token.encode(initial_text, return_tensors="pt")
|
11 |
+
|
12 |
+
token_ids = model.generate(
|
13 |
+
token_text,
|
14 |
+
max_length=250,
|
15 |
+
num_beams=5,
|
16 |
+
repetition_penalty=2.5,
|
17 |
+
early_stopping=True
|
18 |
+
)
|
19 |
+
|
20 |
+
response = text2text_token.decode(token_ids[0], skip_special_tokens=True)
|
21 |
return response
|
22 |
|
23 |
+
# UX
|
24 |
in_para = gr.Textbox(lines=10, label="Paragraph", placeholder="Copy paragraph")
|
25 |
out = gr.Textbox(lines=1, label="Summary")
|
26 |
+
gr.Interface(text2text_summary, inputs=in_para, outputs=out).launch()
|