HemanM commited on
Commit
3ee05fc
·
verified ·
1 Parent(s): 8469bea

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -21
app.py CHANGED
@@ -1,30 +1,22 @@
1
- # app.py — Gradio interface for EvoDecoder conversational chatbot
2
  import gradio as gr
3
  from generate import generate_response
4
 
5
- # Initialize Gradio Chatbot with OpenAI-style message format
6
- with gr.Blocks(title="🧠 Chat with EvoDecoder — Lightweight Conversational AI") as demo:
7
- gr.Markdown("## 🧠 Chat with EvoDecoder — Lightweight Conversational AI")
8
-
9
  chatbot = gr.Chatbot(label="Chat with Evo", type="messages")
10
- msg = gr.Textbox(placeholder="Ask Evo anything...", label="Your message")
11
- clear = gr.Button("Clear Chat")
 
12
 
13
- def chat_fn(history, message):
14
- """Handles each user input and appends Evo's response."""
15
  history = history or []
16
- response = generate_response(message)
17
- history.append({"role": "user", "content": message})
18
  history.append({"role": "assistant", "content": response})
19
- return history
20
-
21
- def clear_fn():
22
- """Clears the chat history."""
23
- return []
24
 
25
- msg.submit(chat_fn, [chatbot, msg], chatbot)
26
- msg.submit(lambda: "", None, msg)
27
- clear.click(clear_fn, outputs=chatbot)
28
 
29
- # Launch the app
30
- demo.launch()
 
1
+ # app.py — Gradio chat interface for EvoDecoder with optional RAG (web search)
2
  import gradio as gr
3
  from generate import generate_response
4
 
5
+ with gr.Blocks(title="🧠 EvoDecoder Chat with RAG") as app:
6
+ gr.Markdown("## 🧠 Chat with EvoDecoder — Now with 🔍 Web Context (RAG)")
 
 
7
  chatbot = gr.Chatbot(label="Chat with Evo", type="messages")
8
+ msg = gr.Textbox(label="Ask Evo anything...", placeholder="e.g., What is quantum computing?")
9
+ use_web = gr.Checkbox(label="🔍 Use Web Context (RAG)", value=True)
10
+ clear = gr.Button("🧹 Clear Chat")
11
 
12
+ def chat_fn(user_message, history, web_flag):
13
+ response = generate_response(user_message, use_web=web_flag)
14
  history = history or []
15
+ history.append({"role": "user", "content": user_message})
 
16
  history.append({"role": "assistant", "content": response})
17
+ return history, ""
 
 
 
 
18
 
19
+ msg.submit(chat_fn, inputs=[msg, chatbot, use_web], outputs=[chatbot, msg])
20
+ clear.click(lambda: ([], ""), outputs=[chatbot, msg])
 
21
 
22
+ app.launch()