Update app.py
Browse files
app.py
CHANGED
@@ -1,23 +1,35 @@
|
|
1 |
-
# app.py —
|
|
|
2 |
import gradio as gr
|
3 |
from generate import generate_response
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
-
|
|
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
history[-1] = (history[-1][0], response)
|
18 |
-
return history
|
19 |
|
20 |
-
|
21 |
-
|
22 |
|
23 |
-
|
|
|
1 |
+
# app.py — Gradio interface for EvoDecoder Chatbot with full conversation context
|
2 |
+
|
3 |
import gradio as gr
|
4 |
from generate import generate_response
|
5 |
|
6 |
+
# Define chat function
|
7 |
+
def chat_fn(history, message):
|
8 |
+
# Merge all past messages to provide conversation context
|
9 |
+
context = ""
|
10 |
+
for item in history:
|
11 |
+
context += f"User: {item['user']}\nAssistant: {item['assistant']}\n"
|
12 |
+
context += f"User: {message}\n"
|
13 |
+
|
14 |
+
# Generate Evo's reply based on full context
|
15 |
+
reply = generate_response(context)
|
16 |
+
|
17 |
+
# Append the new exchange to history
|
18 |
+
history.append({"user": message, "assistant": reply})
|
19 |
+
return history, ""
|
20 |
+
|
21 |
+
# Gradio UI setup
|
22 |
+
with gr.Blocks() as demo:
|
23 |
+
gr.Markdown("## 🧠 Chat with EvoDecoder — A Lightweight Conversational AI")
|
24 |
|
25 |
+
chatbot = gr.Chatbot(label="Chat with Evo", type="messages")
|
26 |
+
state = gr.State([])
|
27 |
|
28 |
+
with gr.Row():
|
29 |
+
msg = gr.Textbox(label="Your message", placeholder="Ask Evo anything...")
|
30 |
+
send_btn = gr.Button("Send")
|
|
|
|
|
31 |
|
32 |
+
send_btn.click(chat_fn, inputs=[state, msg], outputs=[chatbot, msg])
|
33 |
+
msg.submit(chat_fn, inputs=[state, msg], outputs=[chatbot, msg]) # Enter key submits too
|
34 |
|
35 |
+
demo.launch()
|