Spaces:
Runtime error
Runtime error
tomcat commited on
Commit ·
d03165d
1
Parent(s): 0e12a16
Create app.py
Browse filesv1.0 released, It's my first public gradio app.
app.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
#pp = pipeline("question-answering",model="deepset/roberta-base-squad2")
|
| 5 |
+
pp = pipeline("question-answering",model="luhua/chinese_pretrain_mrc_roberta_wwm_ext_large")
|
| 6 |
+
|
| 7 |
+
def qa_fn(ask,ctxt):
|
| 8 |
+
ret = pp(context=ctxt, question=ask);
|
| 9 |
+
ret['entity']='Answer';
|
| 10 |
+
return {"text":ctxt,"entities":[ret]}, ret['answer'], ret['score']
|
| 11 |
+
#注意HighlightedText的用法。有两种不同用法:https://gradio.app/named_entity_recognition/
|
| 12 |
+
# 一种是list of dict ,一种是list of tuple. 详细用法参考https://gradio.app/named_entity_recognition/吧
|
| 13 |
+
|
| 14 |
+
samples= [["乔治的哥哥叫什么名字?","我是小猪佩奇,我是乔治的哥哥,我家住在北京"],["乔治住在哪里呀?","我是小猪佩奇,我是乔治的哥哥,我的家在北京颐和园"]];
|
| 15 |
+
|
| 16 |
+
demo = gr.Interface(qa_fn,
|
| 17 |
+
inputs=[gr.Textbox(label="Question",placeholder='请输入问题'), gr.Textbox(label="Context",lines=10,placeholder="请输入一段文本")],
|
| 18 |
+
outputs=[gr.HighlightedText(label='答案位置'),gr.Textbox(label="答案"),gr.Number(label="Score")],
|
| 19 |
+
examples=samples);
|
| 20 |
+
|
| 21 |
+
demo.launch()
|