Tryacp / app.py
aymnsk's picture
Update app.py
6abbda8 verified
# app.py
import gradio as gr
from agents.programmer import ProgrammerAgent
from agents.debugger import DebuggerAgent
from agents.base_agent import ACPMessage
from firebase.firebase_config import log_message_to_firestore
# Init agents
codebot = ProgrammerAgent()
bugbot = DebuggerAgent()
chat_history = []
def chat_with_bots(user_input):
global chat_history
# Append User message (in red)
chat_history.append(("πŸŸ₯ You", f"<span class='user-msg'>{user_input}</span>"))
# Create ACP messages
msg_to_codebot = ACPMessage(sender="User", receiver="CodeBot", performative="request", content=user_input)
msg_to_bugbot = ACPMessage(sender="User", receiver="BugBot", performative="request", content=user_input)
# Log to Firebase
log_message_to_firestore(msg_to_codebot.to_dict())
log_message_to_firestore(msg_to_bugbot.to_dict())
# Get responses
reply_codebot = codebot.receive_message(msg_to_codebot)
reply_bugbot = bugbot.receive_message(msg_to_bugbot)
# Log replies
log_message_to_firestore(reply_codebot.to_dict())
log_message_to_firestore(reply_bugbot.to_dict())
# Append responses with custom colored bubbles
chat_history.append(("🟩 CodeBot", f"<span class='codebot-msg'>{reply_codebot.content}</span>"))
chat_history.append(("🟧 BugBot", f"<span class='bugbot-msg'>{reply_bugbot.content}</span>"))
return chat_history
# Gradio Blocks App
with gr.Blocks(css="""
.user-msg {
background-color: #ffdddd;
padding: 8px 12px;
border-radius: 10px;
display: inline-block;
}
.codebot-msg {
background-color: #ddffdd;
padding: 8px 12px;
border-radius: 10px;
display: inline-block;
}
.bugbot-msg {
background-color: #ffe5cc;
padding: 8px 12px;
border-radius: 10px;
display: inline-block;
}
.gr-chatbot {
height: 250px !important;
overflow-y: auto;
}
""") as demo:
gr.Markdown("### Mn.o1 ACP Based Bots")
chatbot = gr.Chatbot(label="Chat", bubble_full_width=False, show_copy_button=True)
with gr.Row():
msg_input = gr.Textbox(placeholder="Ask a question...", lines=1, show_label=False)
send_btn = gr.Button("Send", variant="primary")
send_btn.click(chat_with_bots, inputs=msg_input, outputs=chatbot)
msg_input.submit(chat_with_bots, inputs=msg_input, outputs=chatbot)
gr.Markdown(
"""
<div style='text-align: right; font-size: 0.9em; padding-top: 20px;'>
🌐 Connect with me:
<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>
</div>
""",
elem_id="footer"
)
demo.launch()