from transformers import AutoModelForQuestionAnswering, AutoTokenizer, pipeline import gradio as gr nlp = pipeline('question-answering', model='deepset/roberta-base-squad2', tokenizer='deepset/roberta-base-squad2') def qnamodel(context,question): question_set = {'context':context,'question':question} results = nlp(question_set) return results['answer'] interface = gr.Interface(fn=qnamodel, inputs=[gr.inputs.Textbox(lines=7, label="Context"), gr.inputs.Textbox(lines=2, label="Question")], outputs= gr.outputs.Textbox(label="Answer"), title='Context Question Answering') interface.launch(inline=False)