File size: 1,048 Bytes
280866e
91fa53c
280866e
91fa53c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96aa1bc
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
import gradio as gr
from transformers import pipeline

# Load the model from Hugging Face
qa_pipeline = pipeline("question-answering", model="nikhilwani/question_answering")

# Define the QA function
def answer_question(context, question):
    result = qa_pipeline(question=question, context=context)
    return result["answer"]

# Create a Gradio app using the new syntax for Gradio 5.5.0
with gr.Blocks() as demo:
    gr.Markdown("# Question Answering")
    gr.Markdown("Provide context and ask a question to get an answer.")
    
    with gr.Row():
        context_input = gr.Textbox(lines=5, placeholder="Enter the context here...", label="Context")
        question_input = gr.Textbox(placeholder="Ask your question here...", label="Question")
        
    with gr.Row():
        submit_button = gr.Button("Submit")
        output_box = gr.Textbox(label="Answer")

    # Connect the function to the components
    submit_button.click(answer_question, inputs=[context_input, question_input], outputs=output_box)

# Launch the app
demo.launch()