|
|
import gradio as gr |
|
|
from transformers import pipeline |
|
|
|
|
|
|
|
|
qa_model = pipeline("question-answering", model="distilbert-base-cased-distilled-squad") |
|
|
|
|
|
|
|
|
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}" |
|
|
|
|
|
|
|
|
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.", |
|
|
) |
|
|
|
|
|
|
|
|
iface.launch() |
|
|
|