Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load the pretrained QnA pipeline
|
| 5 |
+
qa_pipeline = pipeline("question-answering", model="deepset/roberta-base-squad2")
|
| 6 |
+
|
| 7 |
+
def answer_question(context, question):
|
| 8 |
+
result = qa_pipeline(question=question, context=context)
|
| 9 |
+
return result["answer"]
|
| 10 |
+
|
| 11 |
+
# Gradio interface
|
| 12 |
+
demo = gr.Interface(
|
| 13 |
+
fn=answer_question,
|
| 14 |
+
inputs=[
|
| 15 |
+
gr.Textbox(label="Context (paste an article or passage)", lines=6),
|
| 16 |
+
gr.Textbox(label="Question")
|
| 17 |
+
],
|
| 18 |
+
outputs="text",
|
| 19 |
+
title="Tourism QnA Bot",
|
| 20 |
+
description="Paste some text in the context box, then ask a question about it!"
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
demo.launch()
|