aymnsk commited on
Commit
9fd2f28
Β·
verified Β·
1 Parent(s): f217037

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -58
app.py CHANGED
@@ -4,75 +4,47 @@ import gradio as gr
4
  from agents.programmer import ProgrammerAgent
5
  from agents.debugger import DebuggerAgent
6
  from agents.base_agent import ACPMessage
7
- # log_message_to_firestore(msg.to_dict())
8
 
9
- # Initialize agents
10
  codebot = ProgrammerAgent()
11
  bugbot = DebuggerAgent()
12
 
13
- # Chat history
14
- conversation = []
 
 
15
 
16
- def start_conversation():
17
- global conversation
18
- conversation = [] # reset
19
 
20
- # Initial message from BugBot
21
- msg = bugbot.create_message(
22
- receiver=codebot.name,
23
- performative="request",
24
- content="Can you write a Python function to reverse a list?"
25
- )
26
- conversation.append(str(msg))
27
 
28
- # CodeBot responds
29
- reply = codebot.receive_message(msg)
30
- conversation.append(str(reply))
31
 
32
- return "\n\n".join(conversation)
 
 
 
33
 
34
- def continue_conversation():
35
- if len(conversation) < 2:
36
- return "Please start the conversation first."
 
37
 
38
- # Last reply came from CodeBot β†’ BugBot now responds
39
- last_msg = conversation[-1]
40
- parsed = parse_acp_string(last_msg)
41
- reply = bugbot.receive_message(parsed)
42
- conversation.append(str(reply))
43
 
44
- # CodeBot replies again
45
- reply2 = codebot.receive_message(reply)
46
- conversation.append(str(reply2))
47
 
48
- return "\n\n".join(conversation)
49
 
50
- def parse_acp_string(message_str: str) -> ACPMessage:
51
- """
52
- Convert "[PERFORMATIVE] sender β†’ receiver: content"
53
- back to an ACPMessage object
54
- """
55
- try:
56
- parts = message_str.split("] ", 1)
57
- performative = parts[0][1:].lower()
58
- meta, content = parts[1].split(": ", 1)
59
- sender, receiver = [s.strip() for s in meta.split("β†’")]
60
- return ACPMessage(sender, receiver, performative, content.strip())
61
- except Exception:
62
- return ACPMessage("Unknown", "Unknown", "inform", "Failed to parse message.")
63
-
64
- # Gradio interface
65
- with gr.Blocks(title="BotTalks") as demo:
66
- gr.Markdown("# πŸ€– BotTalks: Programmer vs Debugger\nAgent Communication Protocol Chat")
67
-
68
- chatbox = gr.Textbox(label="Conversation", lines=20)
69
-
70
- with gr.Row():
71
- start_btn = gr.Button("Start Conversation πŸš€")
72
- next_btn = gr.Button("Next Turn πŸ”")
73
-
74
- start_btn.click(start_conversation, outputs=chatbox)
75
- next_btn.click(continue_conversation, outputs=chatbox)
76
-
77
- # Run app
78
  demo.launch()
 
4
  from agents.programmer import ProgrammerAgent
5
  from agents.debugger import DebuggerAgent
6
  from agents.base_agent import ACPMessage
7
+ from firebase.firebase_config import log_message_to_firestore
8
 
9
+ # Init agents
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
+ # Format reply for chat
31
+ full_reply = f"""
32
+ 🧠 **CodeBot** (Programmer):
33
+ {reply_codebot.content}
34
 
35
+ 🐞 **BugBot** (Debugger):
36
+ {reply_bugbot.content}
37
+ """
38
+ return full_reply.strip()
39
 
40
+ # Gradio UI
41
+ with gr.Blocks(title="BotTalks: Chat with 2 AI Agents") as demo:
42
+ gr.Markdown("# πŸ€– BotTalks: Chat with 2 AI Friends!\nAsk anything and see how both agents respond.")
43
+ input_box = gr.Textbox(label="You", placeholder="Ask something like: How do I reverse a list?", lines=2)
44
+ output_box = gr.Textbox(label="Responses", lines=10)
45
 
46
+ send_btn = gr.Button("Send")
 
 
47
 
48
+ send_btn.click(chat_with_bots, inputs=input_box, outputs=output_box)
49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  demo.launch()