LovnishVerma's picture
Update app.py
d519348
raw
history blame contribute delete
808 Bytes
import gradio as gr
from transformers import pipeline
# Load pre-trained question-answering model
qa_model = pipeline("question-answering", model="distilbert-base-cased-distilled-squad")
# Define the question-answering function
def answer_question(context, question):
result = qa_model(context=context, question=question)
answer = result["answer"]
confidence = result["score"]
return f"Answer: {answer}\nConfidence: {confidence:.4f}"
# Create Gradio interface
iface = gr.Interface(
fn=answer_question,
inputs=[gr.Textbox(label="Context"), gr.Textbox(label="Question")],
outputs=gr.Textbox(),
live=True,
title="Question Answering System",
description="Enter a context and a question, and the model will provide an answer.",
)
# Launch the Gradio app
iface.launch()