Spaces:
Sleeping
Sleeping
import gradio as gr | |
from transformers import pipeline | |
# Load the Question Answering pipeline | |
qa_model = pipeline("question-answering", model="distilbert-base-uncased-distilled-squad") | |
def answer_question(context, question): | |
result = qa_model(question=question, context=context) | |
answer = result['answer'] | |
score = result['score'] | |
return answer, f"{score:.2f}" | |
# Define the Gradio interface | |
with gr.Interface( | |
fn=answer_question, | |
inputs=[gr.inputs.Textbox(lines=10, placeholder="Enter the context here..."), gr.inputs.Textbox(lines=2, placeholder="Enter your question here...")], | |
outputs=[gr.outputs.Textbox(label="Answer"), gr.outputs.Textbox(label="Confidence Score")], | |
title="Question Answering System", | |
description="Upload a document and ask questions to get answers based on the context." | |
) as qa_app: | |
qa_app.launch() | |