AskMe-QA-App / app.py
PaulSouvik's picture
Added app.py and requirements.txt
24488a9 verified
# 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()