HemanM commited on
Commit
e9037c9
·
verified ·
1 Parent(s): e80297e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -32
app.py CHANGED
@@ -1,41 +1,35 @@
1
  import gradio as gr
2
  from generate import generate_response
 
3
 
4
- def answer_question(question, context, use_rag, temperature):
5
- if not question.strip():
6
- return "❌ Please enter a question."
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
- with gr.Row():
24
- question = gr.Textbox(label="❓ Question", placeholder="e.g. What is the capital of Japan?")
25
-
26
- context = gr.Textbox(label="📄 Context (Optional)", placeholder="Paste context or leave blank to use RAG", lines=4)
27
 
28
- with gr.Row():
29
- use_rag = gr.Checkbox(label="🔍 Use RAG (Live Web Search)", value=False)
30
- temperature = gr.Slider(0.1, 1.5, value=1.0, step=0.1, label="🔥 Temperature")
31
 
32
- with gr.Row():
33
- submit = gr.Button("Submit")
34
- clear = gr.Button("Clear")
35
 
36
- output = gr.Textbox(label="🤖 Evo's Answer", lines=4)
37
-
38
- submit.click(fn=answer_question, inputs=[question, context, use_rag, temperature], outputs=output)
39
- clear.click(fn=lambda: ("", "", False, 1.0, ""), inputs=[], outputs=[question, context, use_rag, temperature, output])
 
 
 
 
 
 
 
 
 
 
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()