File size: 808 Bytes
17822e0
d519348
17822e0
d519348
 
17822e0
d519348
 
 
 
 
 
17822e0
85c04da
17822e0
d519348
 
17822e0
 
d519348
 
17822e0
 
85c04da
17822e0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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()