aymnsk commited on
Commit
10d7640
·
verified ·
1 Parent(s): 425b91c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -6
app.py CHANGED
@@ -13,6 +13,13 @@ zohaib = DebuggerAgent()
13
 
14
  chat_history = []
15
 
 
 
 
 
 
 
 
16
  def chat_with_friends(user_input):
17
  global chat_history
18
 
@@ -21,16 +28,21 @@ def chat_with_friends(user_input):
21
  msg_riyaz = ACPMessage(sender="You", receiver="Riyaz", performative="request", content=user_input)
22
  msg_zohaib = ACPMessage(sender="You", receiver="Zohaib", performative="request", content=user_input)
23
 
24
- # Log messages
25
  log_message_to_firestore(msg_riyaz.to_dict())
26
  log_message_to_firestore(msg_zohaib.to_dict())
27
 
28
- # Typing delays
29
  time.sleep(1.2)
30
  reply_riyaz = riyaz.receive_message(msg_riyaz)
31
  time.sleep(1.0)
32
  reply_zohaib = zohaib.receive_message(msg_zohaib)
33
 
 
 
 
 
 
 
34
  log_message_to_firestore(reply_riyaz.to_dict())
35
  log_message_to_firestore(reply_zohaib.to_dict())
36
 
@@ -39,7 +51,14 @@ def chat_with_friends(user_input):
39
 
40
  return chat_history
41
 
42
- # Gradio Interface
 
 
 
 
 
 
 
43
  with gr.Blocks(css="""
44
  .user-msg {
45
  background-color: #ffd6d6;
@@ -66,7 +85,6 @@ with gr.Blocks(css="""
66
  height: 250px !important;
67
  overflow-y: auto;
68
  }
69
- /* Circular avatar */
70
  .gr-chatbot .avatar {
71
  border-radius: 50% !important;
72
  height: 38px !important;
@@ -75,17 +93,20 @@ with gr.Blocks(css="""
75
  margin-right: 6px;
76
  }
77
  """) as demo:
78
- gr.Markdown("## 🤖 BotTalks: Chat with Friends Riyaz & Zohaib\nAsk anything and see what your AI friends say!")
79
 
80
  chatbot = gr.Chatbot(label="Group Chat", bubble_full_width=False, show_copy_button=True)
81
 
82
  with gr.Row():
83
- msg_input = gr.Textbox(placeholder="Ask anything, e.g., 'how to sort a list in Python?'", lines=1, show_label=False)
84
  send_btn = gr.Button("Send", variant="primary")
 
85
 
86
  send_btn.click(chat_with_friends, inputs=msg_input, outputs=chatbot)
87
  msg_input.submit(chat_with_friends, inputs=msg_input, outputs=chatbot)
88
 
 
 
89
  gr.Markdown("""
90
  <div style='text-align: right; font-size: 0.9em; padding-top: 15px;'>
91
  🔗 Connect:
 
13
 
14
  chat_history = []
15
 
16
+ # ✅ Memory in RAM
17
+ chat_memory = {
18
+ "riyaz": [],
19
+ "zohaib": []
20
+ }
21
+
22
+ # ✅ Chat function with memory
23
  def chat_with_friends(user_input):
24
  global chat_history
25
 
 
28
  msg_riyaz = ACPMessage(sender="You", receiver="Riyaz", performative="request", content=user_input)
29
  msg_zohaib = ACPMessage(sender="You", receiver="Zohaib", performative="request", content=user_input)
30
 
 
31
  log_message_to_firestore(msg_riyaz.to_dict())
32
  log_message_to_firestore(msg_zohaib.to_dict())
33
 
34
+ # Typing delay
35
  time.sleep(1.2)
36
  reply_riyaz = riyaz.receive_message(msg_riyaz)
37
  time.sleep(1.0)
38
  reply_zohaib = zohaib.receive_message(msg_zohaib)
39
 
40
+ # Store in memory
41
+ chat_memory["riyaz"].append(f"User: {user_input.strip()}")
42
+ chat_memory["riyaz"].append(f"Riyaz: {reply_riyaz.content}")
43
+ chat_memory["zohaib"].append(f"User: {user_input.strip()}")
44
+ chat_memory["zohaib"].append(f"Zohaib: {reply_zohaib.content}")
45
+
46
  log_message_to_firestore(reply_riyaz.to_dict())
47
  log_message_to_firestore(reply_zohaib.to_dict())
48
 
 
51
 
52
  return chat_history
53
 
54
+ # ✅ Reset memory + chat
55
+ def reset_all():
56
+ chat_history.clear()
57
+ chat_memory["riyaz"].clear()
58
+ chat_memory["zohaib"].clear()
59
+ return []
60
+
61
+ # ✅ Gradio Interface
62
  with gr.Blocks(css="""
63
  .user-msg {
64
  background-color: #ffd6d6;
 
85
  height: 250px !important;
86
  overflow-y: auto;
87
  }
 
88
  .gr-chatbot .avatar {
89
  border-radius: 50% !important;
90
  height: 38px !important;
 
93
  margin-right: 6px;
94
  }
95
  """) as demo:
96
+ gr.Markdown("## 🤖 BotTalks: Chat with Friends Riyaz & Zohaib\nAsk anything, watch how they reply 💬")
97
 
98
  chatbot = gr.Chatbot(label="Group Chat", bubble_full_width=False, show_copy_button=True)
99
 
100
  with gr.Row():
101
+ msg_input = gr.Textbox(placeholder="Ask anything like 'how do I write a function?'", lines=1, show_label=False)
102
  send_btn = gr.Button("Send", variant="primary")
103
+ reset_btn = gr.Button("🧹 Reset Memory", variant="secondary")
104
 
105
  send_btn.click(chat_with_friends, inputs=msg_input, outputs=chatbot)
106
  msg_input.submit(chat_with_friends, inputs=msg_input, outputs=chatbot)
107
 
108
+ reset_btn.click(fn=reset_all, inputs=[], outputs=chatbot)
109
+
110
  gr.Markdown("""
111
  <div style='text-align: right; font-size: 0.9em; padding-top: 15px;'>
112
  🔗 Connect: