File size: 2,896 Bytes
9fc4259
 
 
 
 
 
9fd2f28
9fc4259
9fd2f28
9fc4259
 
 
2eaaa46
 
9fd2f28
2eaaa46
 
f6d1de8
 
2eaaa46
f6d1de8
9fd2f28
 
9fc4259
f6d1de8
9fd2f28
 
9fc4259
f6d1de8
9fd2f28
 
9fc4259
2eaaa46
9fd2f28
 
9fc4259
f6d1de8
 
 
2eaaa46
 
4c60640
f6d1de8
2eaaa46
f6d1de8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2eaaa46
a7585a7
9fc4259
a7585a7
9fc4259
2eaaa46
f6d1de8
2eaaa46
9fc4259
2eaaa46
 
6abbda8
3366e1a
 
 
 
 
 
 
 
 
 
 
6abbda8
 
9fc4259
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
# 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()