Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import pipeline
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
question_answer = pipeline('question-answering',model = 'distilbert/distilbert-base-cased-distilled-squad')
|
| 5 |
+
|
| 6 |
+
output = pipe({
|
| 7 |
+
'context': context,
|
| 8 |
+
'question': question
|
| 9 |
+
})
|
| 10 |
+
|
| 11 |
+
def question_answering(context, question):
|
| 12 |
+
|
| 13 |
+
output = question_answer({
|
| 14 |
+
'context': context,
|
| 15 |
+
'question': question
|
| 16 |
+
})
|
| 17 |
+
|
| 18 |
+
return output['answer'], str(output['score'] * 100)
|
| 19 |
+
|
| 20 |
+
iface = gr.Interface(
|
| 21 |
+
fn = question_answering,
|
| 22 |
+
inputs = [
|
| 23 |
+
gr.Textbox(label = "Context", placeholder = "Enter your context here..", lines = 5),
|
| 24 |
+
gr.Textbox(label = "Question", placeholder = "Enter your question", lines = 2)
|
| 25 |
+
],
|
| 26 |
+
outputs = [
|
| 27 |
+
gr.Textbox(label = "Answer", lines = 2),
|
| 28 |
+
gr.Textbox(label = "Accuracy")
|
| 29 |
+
]
|
| 30 |
+
)
|