File size: 830 Bytes
29eebf6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import gradio as gr
from transformers import pipeline

# Load model
qa_pipeline = pipeline("question-answering", model="distilbert-base-cased-distilled-squad")

# Function to generate answers
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"]

# Create Gradio UI
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()