Spaces:
Sleeping
Sleeping
added app
Browse files
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import AutoTokenizer, pipeline
|
| 2 |
+
from optimum.onnxruntime import ORTModelForQuestionAnswering
|
| 3 |
+
import gradio as gr
|
| 4 |
+
model = ORTModelForQuestionAnswering.from_pretrained("optimum/roberta-base-squad2")
|
| 5 |
+
tokenizer = AutoTokenizer.from_pretrained("deepset/roberta-base-squad2")
|
| 6 |
+
|
| 7 |
+
onnx_qa = pipeline("question-answering", model=model, tokenizer=tokenizer)
|
| 8 |
+
|
| 9 |
+
question = "What's my name?"
|
| 10 |
+
context = "My name is Philipp and I live in Nuremberg."
|
| 11 |
+
def get_answer(question):
|
| 12 |
+
pred = onnx_qa(question, context)
|
| 13 |
+
return pred
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
demo = gr.Blocks()
|
| 17 |
+
|
| 18 |
+
with demo():
|
| 19 |
+
with gr.Row():
|
| 20 |
+
question = gr.Textbox(label='Question', lines= 3)
|
| 21 |
+
b1 = gr.Button('Get Answer')
|
| 22 |
+
answer = gr.Textbox(label='Answer', lines=4)
|
| 23 |
+
b1.click(fn = get_answer, inputs=question, outputs=answer)
|
| 24 |
+
|
| 25 |
+
demo.launch()
|
| 26 |
+
|