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()