Update app.py
Browse files
app.py
CHANGED
@@ -1,36 +1,30 @@
|
|
1 |
-
# app.py —
|
2 |
-
|
3 |
import gradio as gr
|
4 |
from generate import generate_response
|
5 |
|
6 |
-
#
|
7 |
-
|
8 |
-
# Build full conversation context from history
|
9 |
-
context = ""
|
10 |
-
for msg in history:
|
11 |
-
context += f"User: {msg['content']}\n" if msg["role"] == "user" else f"Assistant: {msg['content']}\n"
|
12 |
-
context += f"User: {message}\n"
|
13 |
-
|
14 |
-
# Generate reply from Evo
|
15 |
-
reply = generate_response(context)
|
16 |
-
|
17 |
-
# Append user and assistant messages
|
18 |
-
history.append({"role": "user", "content": message})
|
19 |
-
history.append({"role": "assistant", "content": reply})
|
20 |
-
return history, ""
|
21 |
-
|
22 |
-
# Launch Gradio app
|
23 |
-
with gr.Blocks() as demo:
|
24 |
gr.Markdown("## 🧠 Chat with EvoDecoder — Lightweight Conversational AI")
|
25 |
|
26 |
chatbot = gr.Chatbot(label="Chat with Evo", type="messages")
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
demo.launch()
|
|
|
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()
|