Update app.py
Browse files
app.py
CHANGED
|
@@ -15,18 +15,18 @@ chat_history = []
|
|
| 15 |
def chat_with_bots(user_input):
|
| 16 |
global chat_history
|
| 17 |
|
| 18 |
-
# User message
|
| 19 |
-
chat_history.append(("You", user_input))
|
| 20 |
|
| 21 |
-
# Create messages
|
| 22 |
msg_to_codebot = ACPMessage(sender="User", receiver="CodeBot", performative="request", content=user_input)
|
| 23 |
msg_to_bugbot = ACPMessage(sender="User", receiver="BugBot", performative="request", content=user_input)
|
| 24 |
|
| 25 |
-
# Log
|
| 26 |
log_message_to_firestore(msg_to_codebot.to_dict())
|
| 27 |
log_message_to_firestore(msg_to_bugbot.to_dict())
|
| 28 |
|
| 29 |
-
#
|
| 30 |
reply_codebot = codebot.receive_message(msg_to_codebot)
|
| 31 |
reply_bugbot = bugbot.receive_message(msg_to_bugbot)
|
| 32 |
|
|
@@ -34,23 +34,46 @@ def chat_with_bots(user_input):
|
|
| 34 |
log_message_to_firestore(reply_codebot.to_dict())
|
| 35 |
log_message_to_firestore(reply_bugbot.to_dict())
|
| 36 |
|
| 37 |
-
#
|
| 38 |
-
chat_history.append(("
|
| 39 |
-
chat_history.append(("
|
| 40 |
|
| 41 |
return chat_history
|
| 42 |
|
| 43 |
-
# Gradio
|
| 44 |
with gr.Blocks(css="""
|
| 45 |
-
.
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
""") as demo:
|
| 48 |
-
gr.Markdown("###
|
| 49 |
|
| 50 |
-
chatbot = gr.Chatbot(label="
|
| 51 |
|
| 52 |
with gr.Row():
|
| 53 |
-
msg_input = gr.Textbox(placeholder="
|
| 54 |
send_btn = gr.Button("Send", variant="primary")
|
| 55 |
|
| 56 |
send_btn.click(chat_with_bots, inputs=msg_input, outputs=chatbot)
|
|
|
|
| 15 |
def chat_with_bots(user_input):
|
| 16 |
global chat_history
|
| 17 |
|
| 18 |
+
# Append User message (in red)
|
| 19 |
+
chat_history.append(("π₯ You", f"<span class='user-msg'>{user_input}</span>"))
|
| 20 |
|
| 21 |
+
# Create ACP messages
|
| 22 |
msg_to_codebot = ACPMessage(sender="User", receiver="CodeBot", performative="request", content=user_input)
|
| 23 |
msg_to_bugbot = ACPMessage(sender="User", receiver="BugBot", performative="request", content=user_input)
|
| 24 |
|
| 25 |
+
# Log to Firebase
|
| 26 |
log_message_to_firestore(msg_to_codebot.to_dict())
|
| 27 |
log_message_to_firestore(msg_to_bugbot.to_dict())
|
| 28 |
|
| 29 |
+
# Get responses
|
| 30 |
reply_codebot = codebot.receive_message(msg_to_codebot)
|
| 31 |
reply_bugbot = bugbot.receive_message(msg_to_bugbot)
|
| 32 |
|
|
|
|
| 34 |
log_message_to_firestore(reply_codebot.to_dict())
|
| 35 |
log_message_to_firestore(reply_bugbot.to_dict())
|
| 36 |
|
| 37 |
+
# Append responses with custom colored bubbles
|
| 38 |
+
chat_history.append(("π© CodeBot", f"<span class='codebot-msg'>{reply_codebot.content}</span>"))
|
| 39 |
+
chat_history.append(("π§ BugBot", f"<span class='bugbot-msg'>{reply_bugbot.content}</span>"))
|
| 40 |
|
| 41 |
return chat_history
|
| 42 |
|
| 43 |
+
# Gradio Blocks App
|
| 44 |
with gr.Blocks(css="""
|
| 45 |
+
.user-msg {
|
| 46 |
+
background-color: #ffdddd;
|
| 47 |
+
padding: 8px 12px;
|
| 48 |
+
border-radius: 10px;
|
| 49 |
+
display: inline-block;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
.codebot-msg {
|
| 53 |
+
background-color: #ddffdd;
|
| 54 |
+
padding: 8px 12px;
|
| 55 |
+
border-radius: 10px;
|
| 56 |
+
display: inline-block;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
.bugbot-msg {
|
| 60 |
+
background-color: #ffe5cc;
|
| 61 |
+
padding: 8px 12px;
|
| 62 |
+
border-radius: 10px;
|
| 63 |
+
display: inline-block;
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
.gr-chatbot {
|
| 67 |
+
height: 250px !important;
|
| 68 |
+
overflow-y: auto;
|
| 69 |
+
}
|
| 70 |
""") as demo:
|
| 71 |
+
gr.Markdown("### π€ BotTalks: Color-Coded AI Chat")
|
| 72 |
|
| 73 |
+
chatbot = gr.Chatbot(label="Chat", bubble_full_width=False, show_copy_button=True, avatar_images=("π€", "π€"))
|
| 74 |
|
| 75 |
with gr.Row():
|
| 76 |
+
msg_input = gr.Textbox(placeholder="Ask a question...", lines=1, show_label=False)
|
| 77 |
send_btn = gr.Button("Send", variant="primary")
|
| 78 |
|
| 79 |
send_btn.click(chat_with_bots, inputs=msg_input, outputs=chatbot)
|