|
import gradio as gr |
|
from generate import generate_response |
|
|
|
def answer_question(question, context, use_rag, temperature): |
|
if not question.strip(): |
|
return "❌ Please enter a question." |
|
|
|
answer = generate_response( |
|
question=question, |
|
context=context.strip(), |
|
use_rag=use_rag, |
|
temperature=temperature |
|
) |
|
return answer or "(No meaningful response generated.)" |
|
|
|
title = "🧠 EvoRAG — SQuAD-Tuned QA with Optional Web Retrieval" |
|
description = "Ask a question with optional context. Evo was fine-tuned on SQuAD v2. Toggle RAG for live web search if no context is available." |
|
|
|
with gr.Blocks() as demo: |
|
gr.Markdown(f"# {title}") |
|
gr.Markdown(description) |
|
|
|
with gr.Row(): |
|
question = gr.Textbox(label="❓ Question", placeholder="e.g. What is the capital of Japan?") |
|
|
|
context = gr.Textbox(label="📄 Context (Optional)", placeholder="Paste context or leave blank to use RAG", lines=4) |
|
|
|
with gr.Row(): |
|
use_rag = gr.Checkbox(label="🔍 Use RAG (Live Web Search)", value=False) |
|
temperature = gr.Slider(0.1, 1.5, value=1.0, step=0.1, label="🔥 Temperature") |
|
|
|
with gr.Row(): |
|
submit = gr.Button("Submit") |
|
clear = gr.Button("Clear") |
|
|
|
output = gr.Textbox(label="🤖 Evo's Answer", lines=4) |
|
|
|
submit.click(fn=answer_question, inputs=[question, context, use_rag, temperature], outputs=output) |
|
clear.click(fn=lambda: ("", "", False, 1.0, ""), inputs=[], outputs=[question, context, use_rag, temperature, output]) |
|
|
|
demo.launch() |
|
|