File size: 1,046 Bytes
5fd2a0b
 
 
e55e9e1
5fd2a0b
e55e9e1
 
5fd2a0b
 
e55e9e1
5fd2a0b
e55e9e1
5fd2a0b
 
 
 
 
 
 
 
 
e55e9e1
 
5fd2a0b
 
 
 
 
e55e9e1
5fd2a0b
 
 
 
 
 
 
 
 
e55e9e1
5fd2a0b
 
e55e9e1
 
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
36
37
38
39
40
41
42
43
import gradio as gr
from transformers import pipeline

# Load QA Model
qa_pipeline = pipeline(
    task="question-answering",
    model="deepset/roberta-base-squad2"
)

# Prediction Function
def answer_question(context, question):
    if not context.strip() or not question.strip():
        return "Please enter both context and question."

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

    return result["answer"]

# Gradio UI
demo = gr.Interface(
    fn=answer_question,
    inputs=[
        gr.Textbox(
            lines=8,
            label="Context",
            placeholder="Enter paragraph or context here..."
        ),
        gr.Textbox(
            lines=2,
            label="Question",
            placeholder="Ask your question..."
        )
    ],
    outputs=gr.Textbox(label="Answer"),
    title="RoBERTa Question Answering System",
    description="Ask questions from the given context using RoBERTa."
)

# Launch for Hugging Face Spaces
demo.launch(server_name="0.0.0.0", server_port=7860)