Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,6 @@ import gradio as gr
|
|
2 |
from agents.programmer import ProgrammerAgent
|
3 |
from agents.debugger import DebuggerAgent
|
4 |
from agents.base_agent import ACPMessage
|
5 |
-
import json
|
6 |
import os
|
7 |
|
8 |
# Initialize agents
|
@@ -12,7 +11,7 @@ zaid = DebuggerAgent()
|
|
12 |
# In-memory chat
|
13 |
chat_memory = []
|
14 |
|
15 |
-
# Greeting
|
16 |
GREETING_RESPONSES = {
|
17 |
"hi": "Hey there! π",
|
18 |
"hello": "Hello! How can I help?",
|
@@ -33,62 +32,69 @@ def chat(user_input):
|
|
33 |
is_greeting, shortcut = fast_greeting_handler(user_input)
|
34 |
|
35 |
if is_greeting:
|
36 |
-
response_aymaan = shortcut
|
37 |
-
response_zaid = shortcut
|
38 |
else:
|
39 |
-
|
40 |
-
response_aymaan = aymaan.receive_message(
|
41 |
-
|
42 |
-
|
43 |
-
response_zaid = zaid.receive_message(
|
44 |
-
|
45 |
-
|
46 |
-
chat_memory.append({
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
def reset_memory():
|
53 |
global chat_memory
|
54 |
chat_memory = []
|
55 |
return []
|
56 |
|
|
|
57 |
custom_css = """
|
58 |
footer {
|
59 |
margin-top: 2em;
|
60 |
text-align: center;
|
61 |
-
color: #
|
62 |
font-size: 0.9em;
|
63 |
}
|
64 |
-
|
65 |
.gradio-container {
|
66 |
-
background: linear-gradient(to bottom right, #
|
67 |
font-family: 'Segoe UI', sans-serif;
|
68 |
}
|
69 |
-
|
70 |
textarea, .gr-button {
|
71 |
border-radius: 12px !important;
|
72 |
}
|
73 |
-
|
74 |
.gr-button {
|
75 |
background-color: #007bff !important;
|
76 |
color: white !important;
|
77 |
font-weight: bold;
|
78 |
transition: background-color 0.3s ease;
|
79 |
}
|
80 |
-
|
81 |
.gr-button:hover {
|
82 |
background-color: #0056b3 !important;
|
83 |
}
|
84 |
"""
|
85 |
|
86 |
with gr.Blocks(css=custom_css) as demo:
|
87 |
-
gr.Markdown("### π¬ ChatLoop β
|
88 |
-
|
89 |
chatbot = gr.Chatbot(label="Chat", height=400, bubble_full_width=False)
|
|
|
90 |
with gr.Row():
|
91 |
-
msg = gr.Textbox(placeholder="Type your message
|
92 |
send_btn = gr.Button("π¨ Send", scale=1)
|
93 |
clear_btn = gr.Button("π§Ή Clear Chat", variant="secondary")
|
94 |
|
|
|
2 |
from agents.programmer import ProgrammerAgent
|
3 |
from agents.debugger import DebuggerAgent
|
4 |
from agents.base_agent import ACPMessage
|
|
|
5 |
import os
|
6 |
|
7 |
# Initialize agents
|
|
|
11 |
# In-memory chat
|
12 |
chat_memory = []
|
13 |
|
14 |
+
# Greeting responses
|
15 |
GREETING_RESPONSES = {
|
16 |
"hi": "Hey there! π",
|
17 |
"hello": "Hello! How can I help?",
|
|
|
32 |
is_greeting, shortcut = fast_greeting_handler(user_input)
|
33 |
|
34 |
if is_greeting:
|
35 |
+
response_aymaan = shortcut
|
36 |
+
response_zaid = shortcut
|
37 |
else:
|
38 |
+
msg_to_aymaan = ACPMessage(sender="User", receiver="Aymaan", performative="inform", content=user_input)
|
39 |
+
response_aymaan = aymaan.receive_message(msg_to_aymaan).content
|
40 |
+
|
41 |
+
msg_to_zaid = ACPMessage(sender="User", receiver="Zaid", performative="inform", content=user_input)
|
42 |
+
response_zaid = zaid.receive_message(msg_to_zaid).content
|
43 |
+
|
44 |
+
# Simulate message bubbles with alignment and avatars
|
45 |
+
chat_memory.append({
|
46 |
+
"role": "user",
|
47 |
+
"content": f"<div style='text-align:right; margin: 5px 0;'>πββοΈ <strong>You:</strong> {user_input}</div>"
|
48 |
+
})
|
49 |
+
chat_memory.append({
|
50 |
+
"role": "aymaan",
|
51 |
+
"content": f"<div style='text-align:left; margin: 5px 0;'>π€ <strong>Aymaan:</strong> {response_aymaan}</div>"
|
52 |
+
})
|
53 |
+
chat_memory.append({
|
54 |
+
"role": "zaid",
|
55 |
+
"content": f"<div style='text-align:left; margin: 5px 0;'>π οΈ <strong>Zaid:</strong> {response_zaid}</div>"
|
56 |
+
})
|
57 |
+
|
58 |
+
return [(None, item["content"]) for item in chat_memory]
|
59 |
|
60 |
def reset_memory():
|
61 |
global chat_memory
|
62 |
chat_memory = []
|
63 |
return []
|
64 |
|
65 |
+
# CSS Styling
|
66 |
custom_css = """
|
67 |
footer {
|
68 |
margin-top: 2em;
|
69 |
text-align: center;
|
70 |
+
color: #888;
|
71 |
font-size: 0.9em;
|
72 |
}
|
|
|
73 |
.gradio-container {
|
74 |
+
background: linear-gradient(to bottom right, #f4f4f9, #e0eafc);
|
75 |
font-family: 'Segoe UI', sans-serif;
|
76 |
}
|
|
|
77 |
textarea, .gr-button {
|
78 |
border-radius: 12px !important;
|
79 |
}
|
|
|
80 |
.gr-button {
|
81 |
background-color: #007bff !important;
|
82 |
color: white !important;
|
83 |
font-weight: bold;
|
84 |
transition: background-color 0.3s ease;
|
85 |
}
|
|
|
86 |
.gr-button:hover {
|
87 |
background-color: #0056b3 !important;
|
88 |
}
|
89 |
"""
|
90 |
|
91 |
with gr.Blocks(css=custom_css) as demo:
|
92 |
+
gr.Markdown("### π¬ ChatLoop β Talk with Aymaan & Zaid")
|
93 |
+
|
94 |
chatbot = gr.Chatbot(label="Chat", height=400, bubble_full_width=False)
|
95 |
+
chatbot.render_markdown = False # Allow HTML for alignment and avatar
|
96 |
with gr.Row():
|
97 |
+
msg = gr.Textbox(placeholder="Type your message...", show_label=False, lines=1, scale=4)
|
98 |
send_btn = gr.Button("π¨ Send", scale=1)
|
99 |
clear_btn = gr.Button("π§Ή Clear Chat", variant="secondary")
|
100 |
|