File size: 941 Bytes
9a7ccba
 
 
 
 
 
 
 
 
 
 
 
 
8fae716
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
27
28
29
30
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
interface = gr.Interface(
    fn=answer_question,
    inputs=[
        gr.Textbox(lines=10, placeholder="Enter the context here...", label="Context"), 
        gr.Textbox(lines=2, placeholder="Enter your question here...", label="Question")
    ],
    outputs=[
        gr.Textbox(label="Answer"), 
        gr.Textbox(label="Confidence Score")
    ],
    title="Question Answering System",
    description="Upload a document and ask questions to get answers based on the context."
)

if __name__ == "__main__":
    interface.launch()