Update app.py
Browse files
app.py
CHANGED
@@ -1,41 +1,35 @@
|
|
1 |
import gradio as gr
|
2 |
from generate import generate_response
|
|
|
3 |
|
4 |
-
def
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
answer = generate_response(
|
9 |
-
question=question,
|
10 |
-
context=context.strip(),
|
11 |
-
use_rag=use_rag,
|
12 |
-
temperature=temperature
|
13 |
-
)
|
14 |
-
return answer or "(No meaningful response generated.)"
|
15 |
-
|
16 |
-
title = "🧠 EvoRAG — SQuAD-Tuned QA with Optional Web Retrieval"
|
17 |
-
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."
|
18 |
-
|
19 |
-
with gr.Blocks() as demo:
|
20 |
-
gr.Markdown(f"# {title}")
|
21 |
-
gr.Markdown(description)
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
context = gr.Textbox(label="📄 Context (Optional)", placeholder="Paste context or leave blank to use RAG", lines=4)
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
|
32 |
-
|
33 |
-
|
34 |
-
clear = gr.Button("Clear")
|
35 |
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from generate import generate_response
|
3 |
+
from web_search import web_search # RAG fallback
|
4 |
|
5 |
+
def evo_qa(question, context, use_rag, temperature):
|
6 |
+
# If no context and RAG is enabled, fetch from web
|
7 |
+
if not context.strip() and use_rag:
|
8 |
+
context = web_search(question)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
+
# Generate answer using Evo
|
11 |
+
answer = generate_response(prompt=question, external_context=context, temperature=temperature)
|
|
|
|
|
12 |
|
13 |
+
if not answer.strip():
|
14 |
+
return "(No meaningful response generated.)"
|
15 |
+
return answer
|
16 |
|
17 |
+
with gr.Blocks(title="EvoRAG — SQuAD-Tuned QA with Optional Web Retrieval") as demo:
|
18 |
+
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.")
|
|
|
19 |
|
20 |
+
with gr.Row():
|
21 |
+
with gr.Column():
|
22 |
+
question = gr.Textbox(label="❓ Question", placeholder="Enter your question...")
|
23 |
+
context = gr.Textbox(label="📄 Context (Optional)", placeholder="Paste context or leave blank to use RAG")
|
24 |
+
use_rag = gr.Checkbox(label="🔍 Use RAG (Live Web Search)", value=False)
|
25 |
+
temperature = gr.Slider(minimum=0.1, maximum=1.5, value=1.0, label="🔥 Temperature")
|
26 |
+
submit = gr.Button("Submit")
|
27 |
+
clear = gr.Button("Clear")
|
28 |
+
|
29 |
+
with gr.Column():
|
30 |
+
answer = gr.Textbox(label="🤖 Evo's Answer", interactive=False, lines=6)
|
31 |
+
|
32 |
+
submit.click(fn=evo_qa, inputs=[question, context, use_rag, temperature], outputs=answer)
|
33 |
+
clear.click(fn=lambda: ("", "", False, 1.0, ""), inputs=[], outputs=[question, context, use_rag, temperature, answer])
|
34 |
|
35 |
demo.launch()
|