Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
from transformers import AutoModelForQuestionAnswering, AutoTokenizer, pipeline
|
4 |
+
|
5 |
+
model_name = "deepset/roberta-base-squad2"
|
6 |
+
|
7 |
+
nlp = pipeline('question-answering', model=model_name, tokenizer=model_name)
|
8 |
+
|
9 |
+
def chat(context, question):
|
10 |
+
QA_input = {
|
11 |
+
"question" : question,
|
12 |
+
"context" : context
|
13 |
+
}
|
14 |
+
res = nlp(QA_input)
|
15 |
+
|
16 |
+
return res['answer']
|
17 |
+
|
18 |
+
screen = gr.Interface(
|
19 |
+
fn = chat,
|
20 |
+
inputs = [gr.Textbox(lines = 8, placeholder = "Enter your context here π"), gr.Textbox(lines = 2, placeholder = "Enter your question here π")],
|
21 |
+
outputs = gr.Textbox(lines = 10, placeholder = "Your answer will be here soon π"),
|
22 |
+
title="Facilitating the QnA with roberta-base-squad2 π©π»βπ»πβπ»π‘",
|
23 |
+
description="This app aims to facilitate the simple QnA with the provided contextπ‘",
|
24 |
+
theme="soft",
|
25 |
+
)
|
26 |
+
|
27 |
+
screen.launch()
|