Jaehan commited on
Commit
7549352
1 Parent(s): ce377c6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -9
app.py CHANGED
@@ -1,17 +1,26 @@
1
- from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
2
  import gradio as gr
3
 
4
  model_name = "deep-learning-analytics/wikihow-t5-small"
5
- model = AutoModelForSeq2SeqLM.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)
 
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()