Spaces:
Sleeping
Sleeping
File size: 883 Bytes
9a7ccba |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
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()
|