Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,92 +1,67 @@
|
|
1 |
-
# app.py
|
2 |
|
3 |
-
import time
|
4 |
import gradio as gr
|
5 |
from agents.programmer import ProgrammerAgent
|
6 |
from agents.debugger import DebuggerAgent
|
7 |
from agents.base_agent import ACPMessage
|
8 |
|
9 |
-
#
|
10 |
aymaan = ProgrammerAgent()
|
11 |
zaid = DebuggerAgent()
|
12 |
|
13 |
-
|
|
|
14 |
|
15 |
-
#
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
}
|
20 |
|
21 |
-
#
|
22 |
-
|
23 |
-
global chat_history
|
24 |
|
25 |
-
|
26 |
-
|
|
|
27 |
|
28 |
-
|
29 |
-
|
|
|
30 |
|
31 |
-
|
32 |
-
|
|
|
33 |
|
34 |
-
|
35 |
-
chat_memory["aymaan"].append(f"Aymaan: {reply_aymaan.content}")
|
36 |
-
chat_memory["zaid"].append(f"You: {user_input}")
|
37 |
-
chat_memory["zaid"].append(f"Zaid: {reply_zaid.content}")
|
38 |
|
39 |
-
|
40 |
-
|
|
|
|
|
41 |
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
return chat_history
|
47 |
-
|
48 |
-
# Reset button
|
49 |
-
def reset_all():
|
50 |
-
chat_history.clear()
|
51 |
-
chat_memory["aymaan"].clear()
|
52 |
-
chat_memory["zaid"].clear()
|
53 |
-
return []
|
54 |
-
|
55 |
-
# UI
|
56 |
-
with gr.Blocks(css="""
|
57 |
-
.gr-chatbot {
|
58 |
-
height: 250px !important;
|
59 |
-
overflow-y: auto;
|
60 |
-
}
|
61 |
-
.gr-chatbot .avatar {
|
62 |
-
border-radius: 50% !important;
|
63 |
-
height: 38px !important;
|
64 |
-
width: 38px !important;
|
65 |
-
object-fit: cover !important;
|
66 |
-
margin-right: 6px;
|
67 |
-
}
|
68 |
-
""") as demo:
|
69 |
-
gr.Markdown("## 🤖 BotTalks: Chat with Aymaan & Zaid — Your AI Coding Buddies")
|
70 |
-
|
71 |
-
chatbot = gr.Chatbot(label="Group Chat", show_copy_button=True, type="messages")
|
72 |
|
73 |
with gr.Row():
|
74 |
-
|
75 |
-
send_btn = gr.Button("Send",
|
76 |
-
reset_btn = gr.Button("🧹 Reset Memory",
|
77 |
-
|
78 |
-
send_btn.click(
|
79 |
-
|
80 |
-
reset_btn.click(
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
|
|
91 |
|
92 |
demo.launch()
|
|
|
1 |
+
# app/app.py
|
2 |
|
|
|
3 |
import gradio as gr
|
4 |
from agents.programmer import ProgrammerAgent
|
5 |
from agents.debugger import DebuggerAgent
|
6 |
from agents.base_agent import ACPMessage
|
7 |
|
8 |
+
# Instantiate agents
|
9 |
aymaan = ProgrammerAgent()
|
10 |
zaid = DebuggerAgent()
|
11 |
|
12 |
+
# Agent memory
|
13 |
+
memory = []
|
14 |
|
15 |
+
# Chat function
|
16 |
+
def chat(user_input):
|
17 |
+
if not user_input.strip():
|
18 |
+
return memory
|
|
|
19 |
|
20 |
+
# Format user's message
|
21 |
+
memory.append({"role": "user", "content": user_input, "name": "You", "avatar": "🧑", "color": "#ff0000"})
|
|
|
22 |
|
23 |
+
# Create messages for both agents
|
24 |
+
msg_for_aymaan = ACPMessage(sender="You", receiver="Aymaan", performative="inform", content=user_input)
|
25 |
+
msg_for_zaid = ACPMessage(sender="You", receiver="Zaid", performative="inform", content=user_input)
|
26 |
|
27 |
+
# Get responses
|
28 |
+
aymaan_reply = aymaan.receive_message(msg_for_aymaan)
|
29 |
+
zaid_reply = zaid.receive_message(msg_for_zaid)
|
30 |
|
31 |
+
# Append replies to memory
|
32 |
+
memory.append({"role": "assistant", "content": aymaan_reply.content, "name": "Aymaan", "avatar": "💬", "color": "#00cc66"})
|
33 |
+
memory.append({"role": "assistant", "content": zaid_reply.content, "name": "Zaid", "avatar": "🐞", "color": "#ffa500"})
|
34 |
|
35 |
+
return memory
|
|
|
|
|
|
|
36 |
|
37 |
+
# Reset memory
|
38 |
+
def reset():
|
39 |
+
memory.clear()
|
40 |
+
return memory
|
41 |
|
42 |
+
# Custom chat styling
|
43 |
+
with gr.Blocks(theme=gr.themes.Base(), css=".message { border-radius: 999px !important; min-height: 250px; }") as demo:
|
44 |
+
gr.Markdown("## 🤖 BotTalks: Chat with Aymaan & Zaid (TinyLLaMA + Mistral)")
|
45 |
+
chatbot = gr.Chatbot(label="Group Chat", type='messages', show_copy_button=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
|
47 |
with gr.Row():
|
48 |
+
msg = gr.Textbox(placeholder="Say something...", scale=8)
|
49 |
+
send_btn = gr.Button("Send", scale=1)
|
50 |
+
reset_btn = gr.Button("🧹 Reset Memory", scale=1)
|
51 |
+
|
52 |
+
send_btn.click(chat, inputs=[msg], outputs=[chatbot])
|
53 |
+
msg.submit(chat, inputs=[msg], outputs=[chatbot])
|
54 |
+
reset_btn.click(reset, outputs=[chatbot])
|
55 |
+
|
56 |
+
# Footer with social links
|
57 |
+
gr.Markdown(
|
58 |
+
"<div style='text-align: right; font-size: 14px;'>"
|
59 |
+
"🔗 Connect: "
|
60 |
+
"<a href='https://www.linkedin.com/in/aymnsk' target='_blank'>LinkedIn</a> | "
|
61 |
+
"<a href='https://github.com/aymnsk' target='_blank'>GitHub</a> | "
|
62 |
+
"<a href='https://www.instagram.com/damnn_aymn/' target='_blank'>Instagram</a> | "
|
63 |
+
"<a href='https://huggingface.co/aymnsk' target='_blank'>HF</a>"
|
64 |
+
"</div>"
|
65 |
+
)
|
66 |
|
67 |
demo.launch()
|