flichote commited on
Commit
27bab33
1 Parent(s): 1a0ae57

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -14
app.py CHANGED
@@ -1,21 +1,25 @@
1
- from transformers import AutoModelWithLMHead, AutoTokenizer
2
  import gradio as grad
 
 
3
 
4
- text2text_tkn = AutoTokenizer.from_pretrained("mrm8488/t5-base-finetuned-question-generation-ap")
5
- mdl = AutoModelWithLMHead.from_pretrained("mrm8488/t5-base-finetuned-question-generation-ap")
6
 
7
- def text2text(context,answer):
8
- input_text = "answer: %s context: %s </s>" % (answer, context)
9
- features = text2text_tkn ([input_text], return_tensors='pt')
10
 
11
- output = mdl.generate(input_ids=features['input_ids'],
12
- attention_mask=features['attention_mask'],
13
- max_length=64)
 
 
 
 
 
14
 
15
- response=text2text_tkn.decode(output[0])
16
  return response
17
 
18
- context=grad.Textbox(lines=10, label="English", placeholder="Context")
19
- ans=grad.Textbox(lines=1, label="Answer")
20
- out=grad.Textbox(lines=1, label="Genereated Question")
21
- grad.Interface(text2text, inputs=[context,ans], outputs=out).launch()
 
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
 
7
+ def text2text_summary(para):
8
+ initial_txt = para.strip().replace("\n","")
9
+ tkn_text = text2text_tkn.encode(initial_txt, return_tensors="pt")
10
 
11
+ tkn_ids = mdl.generate(
12
+ tkn_text,
13
+ max_length=250,
14
+ num_beams=5,
15
+ repetition_penalty=2.5,
16
+
17
+ early_stopping=True
18
+ )
19
 
20
+ response = text2text_tkn.decode(tkn_ids[0], skip_special_tokens=True)
21
  return response
22
 
23
+ para=grad.Textbox(lines=10, label="Paragraph", placeholder="Copy paragraph")
24
+ out=grad.Textbox(lines=1, label="Summary")
25
+ grad.Interface(text2text_summary, inputs=para, outputs=out).launch()