Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoModelForQuestionAnswering,AutoTokenizer,pipeline
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
model = AutoModelForQuestionAnswering.from_pretrained('uer/roberta-base-chinese-extractive-qa')
|
5 |
+
tokenizer = AutoTokenizer.from_pretrained('uer/roberta-base-chinese-extractive-qa')
|
6 |
+
QA = pipeline('question-answering', model=model, tokenizer=tokenizer)
|
7 |
+
|
8 |
+
|
9 |
+
|
10 |
+
|
11 |
+
def get_out(text1,text2):
|
12 |
+
|
13 |
+
QA_input={'question':text1,'context':text2}
|
14 |
+
|
15 |
+
|
16 |
+
res=QA(QA_input)
|
17 |
+
# res['answer']
|
18 |
+
|
19 |
+
return res['answer']
|
20 |
+
|
21 |
+
|
22 |
+
with gr.Blocks() as demo:
|
23 |
+
with gr.Row():
|
24 |
+
question = gr.Textbox(label='question')
|
25 |
+
greet_btn = gr.Button('compute')
|
26 |
+
context=gr.Textbox(label='context')
|
27 |
+
res=gr.Textbox(label='result')
|
28 |
+
greet_btn.click(fn=get_out,inputs=[question,context],outputs=res)
|
29 |
+
|
30 |
+
demo.launch(server_port=9090)
|
31 |
+
|
32 |
+
|
33 |
+
|