aymnsk commited on
Commit
f6d1de8
Β·
verified Β·
1 Parent(s): 2eaaa46

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -14
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 input
26
  log_message_to_firestore(msg_to_codebot.to_dict())
27
  log_message_to_firestore(msg_to_bugbot.to_dict())
28
 
29
- # Bot responses
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
- # Add to history
38
- chat_history.append(("🧠 CodeBot", reply_codebot.content))
39
- chat_history.append(("🐞 BugBot", reply_bugbot.content))
40
 
41
  return chat_history
42
 
43
- # Gradio interface
44
  with gr.Blocks(css="""
45
- .chatbox { background-color: #f2f2f2; border-radius: 10px; padding: 10px; }
46
- .gr-textbox { border-radius: 8px !important; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  """) as demo:
48
- gr.Markdown("### πŸ’¬ WhatsBot: Talk with CodeBot & BugBot")
49
 
50
- chatbot = gr.Chatbot(label="WhatsApp-style Chat", height=500, bubble_full_width=False, avatar_images=("πŸ‘€", "πŸ€–"))
51
 
52
  with gr.Row():
53
- msg_input = gr.Textbox(placeholder="Type a message like: How to reverse a string in Python?", lines=1, show_label=False)
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)