Syedhd commited on
Commit
672dd1e
·
verified ·
1 Parent(s): c60ae8b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -10
app.py CHANGED
@@ -1,15 +1,25 @@
1
- from transformers import AutoModelForQuestionAnswering, AutoTokenizer, pipeline
2
  import gradio as grad
3
- import ast
 
4
 
5
- mdl_name = "distilbert-base-cased-distilled-squad"
6
- my_pipeline = pipeline('question-answering', model=mdl_name, tokenizer=mdl_name)
7
 
 
 
 
8
 
9
- def answer_question(question,context):
10
- text= "{"+"'question': '"+question+"','context': '"+context+"'}"
11
-
12
- di=ast.literal_eval(text)
13
- response = my_pipeline(di)
 
 
 
 
 
14
  return response
15
- grad.Interface(answer_question, inputs=["text","text"], outputs="text").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()