File size: 790 Bytes
7b8f226
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86fa319
7b8f226
 
 
 
 
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
31
32
33
34
35
import gradio as gr
from transformers import pipeline

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

# Function
def answer(context, question):
    if context.strip() == "" or question.strip() == "":
        return "Please enter context and question."

    result = qa_pipeline(
        question=question,
        context=context
    )

    return result["answer"]

# UI
demo = gr.Interface(
    fn=answer,
    inputs=[
        gr.Textbox(lines=8, label="Context"),
        gr.Textbox(lines=2, label="Question")
    ],
    outputs="text",
    title="🔍 RAG-QA System",
    description="Ask questions from given context.",
    theme=gr.themes.Soft()
)

demo.launch(server_name="0.0.0.0", server_port=7860)