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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -21
app.py CHANGED
@@ -10,43 +10,50 @@ from firebase.firebase_config import log_message_to_firestore
10
  codebot = ProgrammerAgent()
11
  bugbot = DebuggerAgent()
12
 
 
 
13
  def chat_with_bots(user_input):
14
- # Send same input to both agents
 
 
 
 
 
15
  msg_to_codebot = ACPMessage(sender="User", receiver="CodeBot", performative="request", content=user_input)
16
  msg_to_bugbot = ACPMessage(sender="User", receiver="BugBot", performative="request", content=user_input)
17
 
18
- # Log inputs
19
  log_message_to_firestore(msg_to_codebot.to_dict())
20
  log_message_to_firestore(msg_to_bugbot.to_dict())
21
 
22
- # Get both responses
23
  reply_codebot = codebot.receive_message(msg_to_codebot)
24
  reply_bugbot = bugbot.receive_message(msg_to_bugbot)
25
 
26
- # Log responses
27
  log_message_to_firestore(reply_codebot.to_dict())
28
  log_message_to_firestore(reply_bugbot.to_dict())
29
 
30
- full_reply = f"""
31
- ### 🧠 **CodeBot** (Programmer)
32
- {reply_codebot.content}
33
-
34
- ---
35
-
36
- ### 🐞 **BugBot** (Debugger)
37
- {reply_bugbot.content}
38
- """
39
 
40
- return full_reply.strip()
 
 
 
 
 
41
 
42
- # Gradio UI
43
- with gr.Blocks(title="BotTalks: Chat with 2 AI Agents") as demo:
44
- gr.Markdown("# 🤖 BotTalks: Chat with 2 AI Friends!\nAsk anything and see how both agents respond.")
45
- input_box = gr.Textbox(label="You", placeholder="Ask something like: How do I reverse a list?", lines=2)
46
- output_box = gr.Markdown()
47
 
48
- send_btn = gr.Button("Send")
 
 
49
 
50
- send_btn.click(chat_with_bots, inputs=input_box, outputs=output_box)
 
51
 
52
  demo.launch()
 
10
  codebot = ProgrammerAgent()
11
  bugbot = DebuggerAgent()
12
 
13
+ chat_history = []
14
+
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
 
33
+ # Log replies
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)
57
+ msg_input.submit(chat_with_bots, inputs=msg_input, outputs=chatbot)
58
 
59
  demo.launch()