Spaces:
Sleeping
Sleeping
| # app.py | |
| from transformers import pipeline | |
| import gradio as gr | |
| # Load the Question Answering pipeline with the selected model | |
| qa_pipeline = pipeline("question-answering", model="deepset/roberta-base-squad2") | |
| # Define the function that performs question answering | |
| def answer_question(context, question): | |
| result = qa_pipeline(question=question, context=context) | |
| return result['answer'] | |
| # Build the Gradio UI | |
| with gr.Blocks() as demo: | |
| gr.Markdown(""" | |
| # π AskMe: AI Question Answering App | |
| Enter a paragraph and ask any related question. The AI will find the most relevant answer. | |
| ## π Instructions for Users: | |
| - Provide a **Context** (short paragraph or passage). | |
| - Enter a **Question** based on that context. | |
| - The AI will return the most accurate answer found **within the context**. | |
| β οΈ **Note**: | |
| - The question **must be closely related** to the context. | |
| - **Irrelevant or slightly off-topic questions** may return **inaccurate or biased results**. | |
| """) | |
| with gr.Row(): | |
| context_input = gr.Textbox( | |
| label="π Context (Paragraph)", | |
| lines=8, | |
| placeholder="e.g., The Amazon River flows through Brazil, Peru, and Colombia. It is the second-longest river in the world..." | |
| ) | |
| question_input = gr.Textbox( | |
| label="β Your Question", | |
| placeholder="e.g., Which countries does the Amazon River flow through?" | |
| ) | |
| answer_output = gr.Textbox(label="β AI Answer") | |
| submit_button = gr.Button("Get Answer") | |
| submit_button.click(fn=answer_question, inputs=[context_input, question_input], outputs=answer_output) | |
| demo.launch() | |