|
import gradio as gr |
|
from transformers import pipeline |
|
|
|
|
|
qa_pipeline = pipeline("question-answering", model="distilbert-base-cased-distilled-squad") |
|
|
|
|
|
def answer_question(context, question): |
|
if not context or not question: |
|
return "⚠️ Please enter both a text passage and a question!" |
|
result = qa_pipeline(question=question, context=context) |
|
return result["answer"] |
|
|
|
|
|
gr.Interface( |
|
fn=answer_question, |
|
inputs=[gr.Textbox(lines=7, placeholder="Enter your text passage here..."), gr.Textbox(placeholder="Ask a question based on the text...")], |
|
outputs="text", |
|
title="🤔 AI Q&A Assistant", |
|
description="Enter a passage and ask a question about it. The AI will find the best answer for you!", |
|
allow_flagging="never" |
|
).launch() |