Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from agents.programmer import ProgrammerAgent | |
| from agents.debugger import DebuggerAgent | |
| from agents.base_agent import ACPMessage | |
| aymaan = ProgrammerAgent() | |
| zaid = DebuggerAgent() | |
| chat_memory = [] | |
| def chat(user_input): | |
| if not user_input.strip(): | |
| return chat_memory | |
| user_msg = ACPMessage(sender="User", receiver="Aymaan", performative="inform", content=user_input) | |
| # Handle greetings fast | |
| greetings = ["hi", "hello", "hey", "how are you", "yo"] | |
| if user_input.lower().strip() in greetings: | |
| response_aymaan = ACPMessage(sender="Aymaan", receiver="User", performative="inform", content="Hey there! π") | |
| response_zaid = ACPMessage(sender="Zaid", receiver="User", performative="inform", content="Hello buddy! π") | |
| else: | |
| response_aymaan = aymaan.receive_message(user_msg) | |
| response_zaid = zaid.receive_message(user_msg) | |
| chat_memory.append({"role": "user", "content": user_input}) | |
| chat_memory.append({"role": "aymaan", "content": response_aymaan.content}) | |
| chat_memory.append({"role": "zaid", "content": response_zaid.content}) | |
| return chat_memory | |
| def reset_memory(): | |
| global chat_memory | |
| chat_memory = [] | |
| return chat_memory | |
| with gr.Blocks(css="footer {margin-top: 2em; text-align: center;}") as demo: | |
| gr.Markdown("## π€ BotTalks: Chat with 2 AI Friends!\nAsk anything and see what Aymaan and Zaid say.") | |
| chatbot = gr.Chatbot(label="Group Chat", type='messages', height=250) | |
| msg = gr.Textbox(label="You") | |
| send_btn = gr.Button("Send") | |
| clear_btn = gr.Button("π§Ή Reset Memory") | |
| with gr.Row(): | |
| pass # buttons already declared and auto-rendered | |
| send_btn.click(chat, inputs=msg, outputs=chatbot) | |
| clear_btn.click(reset_memory, outputs=chatbot) | |
| gr.HTML(""" | |
| <footer> | |
| π Connect: | |
| <a href="https://www.linkedin.com/in/aymnsk" target="_blank">LinkedIn</a> | | |
| <a href="https://github.com/aymnsk" target="_blank">GitHub</a> | | |
| <a href="https://www.instagram.com/damnn_aymn/" target="_blank">Instagram</a> | | |
| <a href="https://huggingface.co/aymnsk" target="_blank">HF</a> | |
| </footer> | |
| """) | |
| if __name__ == "__main__": | |
| demo.launch() | |