File size: 786 Bytes
77229ef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import sys
from transformers import pipeline
import gradio as gr

model = pipeline('question-answering', model='deepset/tinyroberta-squad2', tokenizer='deepset/tinyroberta-squad2')

def qa(passage, question):
    question = question
    context = passage
    nlp_input = {
        'question': question,
        'context': context
    }

    return model(nlp_input)['answer']

passage = "The quick brown fox jumped over the lazy dog."
question = "Who jumps over the lazy dog?"

iface = gr.Interface(qa,
                        title="Question Answering using RoBERTa",
                        inputs=[gr.inputs.Textbox(lines=15), "text"],
                        outputs=["text"],
                        examples=[["{}".format(passage), "{}".format(question)]])
iface.launch()