Spaces:
Sleeping
Sleeping
File size: 3,307 Bytes
425b91c d9e25cb 406e442 cef70b2 9fc4259 e9337b4 5d74208 e9337b4 b84b954 2eaaa46 34cba3d e9337b4 406e442 e9337b4 406e442 5f9aa9b cef70b2 b84b954 e9337b4 bf19c1f e9337b4 34cba3d 406e442 34cba3d b84b954 cef70b2 b84b954 34cba3d bf19c1f 34cba3d bf19c1f 34cba3d bf19c1f 34cba3d bf19c1f 34cba3d bf19c1f 34cba3d bf19c1f 406e442 cef70b2 2845c62 cef70b2 bf19c1f cef70b2 b84b954 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
import gradio as gr
from agents.programmer import ProgrammerAgent
from agents.debugger import DebuggerAgent
from agents.base_agent import ACPMessage
import os
# Initialize agents
aymaan = ProgrammerAgent()
zaid = DebuggerAgent()
# In-memory chat
chat_memory = []
# Greeting responses
GREETING_RESPONSES = {
"hi": "Hey there! π",
"hello": "Hello! How can I help?",
"how are you": "Doing great! Thanks for asking π",
}
def fast_greeting_handler(msg):
lowered = msg.lower()
for greeting in GREETING_RESPONSES:
if greeting in lowered:
return True, GREETING_RESPONSES[greeting]
return False, ""
def chat(user_input):
if not user_input.strip():
return chat_memory
is_greeting, shortcut = fast_greeting_handler(user_input)
if is_greeting:
response_aymaan = shortcut
response_zaid = shortcut
else:
msg_to_aymaan = ACPMessage(sender="User", receiver="Aymaan", performative="inform", content=user_input)
response_aymaan = aymaan.receive_message(msg_to_aymaan).content
msg_to_zaid = ACPMessage(sender="User", receiver="Zaid", performative="inform", content=user_input)
response_zaid = zaid.receive_message(msg_to_zaid).content
# Simulate message bubbles with alignment and avatars
chat_memory.append({
"role": "user",
"content": f"<div style='text-align:right; margin: 5px 0;'>πββοΈ <strong>You:</strong> {user_input}</div>"
})
chat_memory.append({
"role": "aymaan",
"content": f"<div style='text-align:left; margin: 5px 0;'>π€ <strong>Aymaan:</strong> {response_aymaan}</div>"
})
chat_memory.append({
"role": "zaid",
"content": f"<div style='text-align:left; margin: 5px 0;'>π οΈ <strong>Zaid:</strong> {response_zaid}</div>"
})
return [(None, item["content"]) for item in chat_memory]
def reset_memory():
global chat_memory
chat_memory = []
return []
# CSS Styling
custom_css = """
footer {
margin-top: 2em;
text-align: center;
color: #888;
font-size: 0.9em;
}
.gradio-container {
background: linear-gradient(to bottom right, #f4f4f9, #e0eafc);
font-family: 'Segoe UI', sans-serif;
}
textarea, .gr-button {
border-radius: 12px !important;
}
.gr-button {
background-color: #007bff !important;
color: white !important;
font-weight: bold;
transition: background-color 0.3s ease;
}
.gr-button:hover {
background-color: #0056b3 !important;
}
"""
with gr.Blocks(css=custom_css) as demo:
gr.Markdown("### π¬ ChatLoop β Talk with Aymaan & Zaid")
chatbot = gr.Chatbot(label="Chat", height=400, bubble_full_width=False)
chatbot.render_markdown = False # Allow HTML for alignment and avatar
with gr.Row():
msg = gr.Textbox(placeholder="Type your message...", show_label=False, lines=1, scale=4)
send_btn = gr.Button("π¨ Send", scale=1)
clear_btn = gr.Button("π§Ή Clear Chat", variant="secondary")
send_btn.click(chat, inputs=msg, outputs=chatbot)
clear_btn.click(reset_memory, outputs=chatbot)
gr.HTML("""
<footer>
Built with β€οΈ by <a href="https://github.com/aymnsk" target="_blank">aymnsk</a>
</footer>
""")
if __name__ == "__main__":
demo.launch()
|