|
import gradio as gr |
|
from generate import generate_response |
|
from web_search import web_search |
|
|
|
def evo_qa(question, context, use_rag, temperature): |
|
|
|
if not context.strip() and use_rag: |
|
context = web_search(question) |
|
|
|
|
|
answer = generate_response(prompt=question, external_context=context, temperature=temperature) |
|
|
|
if not answer.strip(): |
|
return "(No meaningful response generated.)" |
|
return answer |
|
|
|
with gr.Blocks(title="EvoRAG — SQuAD-Tuned QA with Optional Web Retrieval") as demo: |
|
gr.Markdown("🧠 **EvoRAG — SQuAD-Tuned QA with Optional Web Retrieval**\nAsk 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.Row(): |
|
with gr.Column(): |
|
question = gr.Textbox(label="❓ Question", placeholder="Enter your question...") |
|
context = gr.Textbox(label="📄 Context (Optional)", placeholder="Paste context or leave blank to use RAG") |
|
use_rag = gr.Checkbox(label="🔍 Use RAG (Live Web Search)", value=False) |
|
temperature = gr.Slider(minimum=0.1, maximum=1.5, value=1.0, label="🔥 Temperature") |
|
submit = gr.Button("Submit") |
|
clear = gr.Button("Clear") |
|
|
|
with gr.Column(): |
|
answer = gr.Textbox(label="🤖 Evo's Answer", interactive=False, lines=6) |
|
|
|
submit.click(fn=evo_qa, inputs=[question, context, use_rag, temperature], outputs=answer) |
|
clear.click(fn=lambda: ("", "", False, 1.0, ""), inputs=[], outputs=[question, context, use_rag, temperature, answer]) |
|
|
|
demo.launch() |
|
|