Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
from transformers import pipeline
|
| 4 |
+
import gradio as gr
|
| 5 |
+
|
| 6 |
+
model = pipeline('question-answering', model='deepset/tinyroberta-squad2', tokenizer='deepset/tinyroberta-squad2')
|
| 7 |
+
|
| 8 |
+
def qa(passage, question):
|
| 9 |
+
question = question
|
| 10 |
+
context = passage
|
| 11 |
+
nlp_input = {
|
| 12 |
+
'question': question,
|
| 13 |
+
'context': context
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
return model(nlp_input)['answer']
|
| 17 |
+
|
| 18 |
+
passage = "The quick brown fox jumped over the lazy dog."
|
| 19 |
+
question = "Who jumps over the lazy dog?"
|
| 20 |
+
|
| 21 |
+
iface = gr.Interface(qa,
|
| 22 |
+
title="Question Answering using RoBERTa",
|
| 23 |
+
inputs=[gr.inputs.Textbox(lines=15), "text"],
|
| 24 |
+
outputs=["text"],
|
| 25 |
+
examples=[["{}".format(passage), "{}".format(question)]])
|
| 26 |
+
iface.launch()
|