HemanM commited on
Commit
5cef79d
·
verified ·
1 Parent(s): b37c655

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -23
app.py CHANGED
@@ -1,31 +1,28 @@
1
  import gradio as gr
2
  from generate import generate_response
3
- from web_search import web_search
4
 
5
- def chat_with_evo(prompt, temperature=1.0, use_rag=False):
6
  try:
7
- context = web_search(prompt) if use_rag else ""
8
- response = generate_response(prompt, temperature=temperature, external_context=context)
9
- return response if response else "(No meaningful response generated.)"
10
  except Exception as e:
11
- return f"Error: {str(e)}"
12
 
13
- with gr.Blocks(title="EvoRAG Chatbot") as demo:
14
- gr.Markdown("## 🧠 EvoRAG Lightweight Chatbot with Real-Time Retrieval")
15
 
16
- with gr.Row():
17
- prompt = gr.Textbox(label="💬 Ask Anything", placeholder="Type your question here...", lines=2)
18
- response = gr.Textbox(label="🤖 Evo's Answer", interactive=False)
 
 
 
 
 
 
 
 
 
19
 
20
- with gr.Row():
21
- temp = gr.Slider(0.1, 1.5, step=0.1, value=1.0, label="🔥 Temperature")
22
- use_rag = gr.Checkbox(label="🔍 Use RAG (live web context)", value=True)
23
-
24
- with gr.Row():
25
- clear_btn = gr.Button("🧹 Clear")
26
- send_btn = gr.Button("🚀 Ask Evo")
27
-
28
- send_btn.click(fn=chat_with_evo, inputs=[prompt, temp, use_rag], outputs=response)
29
- clear_btn.click(fn=lambda: ("", ""), inputs=[], outputs=[prompt, response])
30
-
31
- demo.launch()
 
1
  import gradio as gr
2
  from generate import generate_response
 
3
 
4
+ def chat_interface(question, context, use_rag, temperature):
5
  try:
6
+ answer = generate_response(question, context, use_rag=use_rag, temperature=temperature)
7
+ return answer if answer else "(No meaningful response generated.)"
 
8
  except Exception as e:
9
+ return f"(Error: {str(e)})"
10
 
11
+ title = "🧠 EvoRAG SQuAD-Tuned QA with Optional Web Retrieval"
12
+ description = "Ask a question with optional context. Evo was fine-tuned on SQuAD v2.\nToggle RAG for live web search if no context is available."
13
 
14
+ iface = gr.Interface(
15
+ fn=chat_interface,
16
+ inputs=[
17
+ gr.Textbox(label="❓ Question"),
18
+ gr.Textbox(label="📄 Context (Optional)", lines=5, placeholder="Paste context or leave blank to use RAG"),
19
+ gr.Checkbox(label="🔍 Use RAG (Live Web Search)"),
20
+ gr.Slider(0.1, 1.5, value=1.0, label="🔥 Temperature")
21
+ ],
22
+ outputs=gr.Textbox(label="🤖 Evo's Answer"),
23
+ title=title,
24
+ description=description,
25
+ )
26
 
27
+ if __name__ == "__main__":
28
+ iface.launch()