Update app.py
Browse files
app.py
CHANGED
@@ -1,30 +1,22 @@
|
|
1 |
-
# app.py — Gradio interface for EvoDecoder
|
2 |
import gradio as gr
|
3 |
from generate import generate_response
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
gr.Markdown("## 🧠 Chat with EvoDecoder — Lightweight Conversational AI")
|
8 |
-
|
9 |
chatbot = gr.Chatbot(label="Chat with Evo", type="messages")
|
10 |
-
msg = gr.Textbox(
|
11 |
-
|
|
|
12 |
|
13 |
-
def chat_fn(history,
|
14 |
-
|
15 |
history = history or []
|
16 |
-
|
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,
|
26 |
-
|
27 |
-
clear.click(clear_fn, outputs=chatbot)
|
28 |
|
29 |
-
|
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()
|
|