| from transformers import pipeline | |
| import gradio as gr | |
| qa_pipeline = pipeline( | |
| "question-answering", | |
| model="deepset/roberta-base-squad2" | |
| ) | |
| def answer_question(context, question): | |
| result = qa_pipeline({ | |
| "context": context, | |
| "question": question | |
| }) | |
| return result["answer"] | |
| iface = gr.Interface( | |
| fn=answer_question, | |
| inputs=[ | |
| gr.Textbox(lines=6, label="Context"), | |
| gr.Textbox(label="Question") | |
| ], | |
| outputs="text", | |
| title="Extractive Question Answering" | |
| ) | |
| iface.launch() |