Timing0311 commited on
Commit
bd27b28
1 Parent(s): 2dac158

Add Q&A job

Browse files
Files changed (1) hide show
  1. app.py +17 -0
app.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoModelForQuestionAnswering, AutoTokenizer, pipeline
2
+ import gradio as grad
3
+ import ast
4
+ mdl_name = "deepset/roberta-base-squad2"
5
+ my_pipeline = pipeline('question-answering', model=mdl_name, tokenizer=mdl_name)
6
+ def answer_question(question,context):
7
+ text= "{"+"'question': '"+question+"','context': '"+context+"'}"
8
+ di=ast.literal_eval(text)
9
+ response = my_pipeline(di)
10
+ return response
11
+ grad.Interface(answer_question, inputs=["text","text"], outputs="text").launch()
12
+ text = grad.inputs.Textbox(placeholder="Let's chat together")
13
+ grad.Interface(fn=converse,
14
+ theme="default",
15
+ inputs=[text, "state"],
16
+ outputs=["html", "state"],
17
+ css=css).launch()