|
import gradio as gr |
|
from transformers import pipeline |
|
|
|
|
|
qa_pipeline = pipeline("question-answering", model="nikhilwani/question_answering") |
|
|
|
|
|
def answer_question(context, question): |
|
result = qa_pipeline(question=question, context=context) |
|
return result["answer"] |
|
|
|
|
|
with gr.Blocks() as demo: |
|
gr.Markdown("# Question Answering") |
|
gr.Markdown("Provide context and ask a question to get an answer.") |
|
|
|
with gr.Row(): |
|
context_input = gr.Textbox(lines=5, placeholder="Enter the context here...", label="Context") |
|
question_input = gr.Textbox(placeholder="Ask your question here...", label="Question") |
|
|
|
with gr.Row(): |
|
submit_button = gr.Button("Submit") |
|
output_box = gr.Textbox(label="Answer") |
|
|
|
|
|
submit_button.click(answer_question, inputs=[context_input, question_input], outputs=output_box) |
|
|
|
|
|
demo.launch() |
|
|