File size: 1,096 Bytes
a194712
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import gradio as gr
from transformers import AutoModelForQuestionAnswering, AutoTokenizer, pipeline

model_name = "IProject-10/roberta-base-finetuned-squad2"
nlp = pipeline("question-answering", model=model_name, tokenizer=model_name)

def predict(context, question):
    res = nlp({"question": question, "context": context})
    return res["answer"]

md = """
"""

context = "The Amazon rainforest, also known in English as Amazonia or the Amazon Jungle, is a moist broadleaf forest that covers most of the Amazon basin of South America..."
question = "Which continent is the Amazon rainforest in?"

apple_context = "An apple is an edible fruit produced by an apple tree (Malus domestica)..."
apple_question = "How many years have apples been grown for?"

gr.Interface(
    predict,
    inputs=[
        gr.Textbox(lines=7, value=context, label="Context Paragraph"),
        gr.Textbox(lines=2, value=question, label="Question"),
    ],
    outputs=gr.Textbox(label="Answer"),
    examples=[[apple_context, apple_question]],
    title="Question Answering System",
    description=md,
).launch()