aymnsk commited on
Commit
34cba3d
Β·
verified Β·
1 Parent(s): bf19c1f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -25
app.py CHANGED
@@ -2,7 +2,6 @@ import gradio as gr
2
  from agents.programmer import ProgrammerAgent
3
  from agents.debugger import DebuggerAgent
4
  from agents.base_agent import ACPMessage
5
- import json
6
  import os
7
 
8
  # Initialize agents
@@ -12,7 +11,7 @@ zaid = DebuggerAgent()
12
  # In-memory chat
13
  chat_memory = []
14
 
15
- # Greeting shortcuts
16
  GREETING_RESPONSES = {
17
  "hi": "Hey there! πŸ‘‹",
18
  "hello": "Hello! How can I help?",
@@ -33,62 +32,69 @@ def chat(user_input):
33
  is_greeting, shortcut = fast_greeting_handler(user_input)
34
 
35
  if is_greeting:
36
- response_aymaan = shortcut + " (Aymaan)"
37
- response_zaid = shortcut + " (Zaid)"
38
  else:
39
- user_msg = ACPMessage(sender="User", receiver="Aymaan", performative="inform", content=user_input)
40
- response_aymaan = aymaan.receive_message(user_msg).content
41
-
42
- user_msg = ACPMessage(sender="User", receiver="Zaid", performative="inform", content=user_input)
43
- response_zaid = zaid.receive_message(user_msg).content
44
-
45
- chat_memory.append({"role": "You", "content": user_input})
46
- chat_memory.append({"role": "Aymaan", "content": response_aymaan})
47
- chat_memory.append({"role": "Zaid", "content": response_zaid})
48
-
49
- formatted = [(item["role"], item["content"]) for item in chat_memory]
50
- return formatted
 
 
 
 
 
 
 
 
 
51
 
52
  def reset_memory():
53
  global chat_memory
54
  chat_memory = []
55
  return []
56
 
 
57
  custom_css = """
58
  footer {
59
  margin-top: 2em;
60
  text-align: center;
61
- color: #999;
62
  font-size: 0.9em;
63
  }
64
-
65
  .gradio-container {
66
- background: linear-gradient(to bottom right, #f0f2f5, #dbe6f3);
67
  font-family: 'Segoe UI', sans-serif;
68
  }
69
-
70
  textarea, .gr-button {
71
  border-radius: 12px !important;
72
  }
73
-
74
  .gr-button {
75
  background-color: #007bff !important;
76
  color: white !important;
77
  font-weight: bold;
78
  transition: background-color 0.3s ease;
79
  }
80
-
81
  .gr-button:hover {
82
  background-color: #0056b3 !important;
83
  }
84
  """
85
 
86
  with gr.Blocks(css=custom_css) as demo:
87
- gr.Markdown("### πŸ’¬ ChatLoop β€” Your Dual AI Chat")
88
-
89
  chatbot = gr.Chatbot(label="Chat", height=400, bubble_full_width=False)
 
90
  with gr.Row():
91
- msg = gr.Textbox(placeholder="Type your message here...", show_label=False, lines=1, max_lines=4, scale=4)
92
  send_btn = gr.Button("πŸ“¨ Send", scale=1)
93
  clear_btn = gr.Button("🧹 Clear Chat", variant="secondary")
94
 
 
2
  from agents.programmer import ProgrammerAgent
3
  from agents.debugger import DebuggerAgent
4
  from agents.base_agent import ACPMessage
 
5
  import os
6
 
7
  # Initialize agents
 
11
  # In-memory chat
12
  chat_memory = []
13
 
14
+ # Greeting responses
15
  GREETING_RESPONSES = {
16
  "hi": "Hey there! πŸ‘‹",
17
  "hello": "Hello! How can I help?",
 
32
  is_greeting, shortcut = fast_greeting_handler(user_input)
33
 
34
  if is_greeting:
35
+ response_aymaan = shortcut
36
+ response_zaid = shortcut
37
  else:
38
+ msg_to_aymaan = ACPMessage(sender="User", receiver="Aymaan", performative="inform", content=user_input)
39
+ response_aymaan = aymaan.receive_message(msg_to_aymaan).content
40
+
41
+ msg_to_zaid = ACPMessage(sender="User", receiver="Zaid", performative="inform", content=user_input)
42
+ response_zaid = zaid.receive_message(msg_to_zaid).content
43
+
44
+ # Simulate message bubbles with alignment and avatars
45
+ chat_memory.append({
46
+ "role": "user",
47
+ "content": f"<div style='text-align:right; margin: 5px 0;'>πŸ™‹β€β™‚οΈ <strong>You:</strong> {user_input}</div>"
48
+ })
49
+ chat_memory.append({
50
+ "role": "aymaan",
51
+ "content": f"<div style='text-align:left; margin: 5px 0;'>πŸ€– <strong>Aymaan:</strong> {response_aymaan}</div>"
52
+ })
53
+ chat_memory.append({
54
+ "role": "zaid",
55
+ "content": f"<div style='text-align:left; margin: 5px 0;'>πŸ› οΈ <strong>Zaid:</strong> {response_zaid}</div>"
56
+ })
57
+
58
+ return [(None, item["content"]) for item in chat_memory]
59
 
60
  def reset_memory():
61
  global chat_memory
62
  chat_memory = []
63
  return []
64
 
65
+ # CSS Styling
66
  custom_css = """
67
  footer {
68
  margin-top: 2em;
69
  text-align: center;
70
+ color: #888;
71
  font-size: 0.9em;
72
  }
 
73
  .gradio-container {
74
+ background: linear-gradient(to bottom right, #f4f4f9, #e0eafc);
75
  font-family: 'Segoe UI', sans-serif;
76
  }
 
77
  textarea, .gr-button {
78
  border-radius: 12px !important;
79
  }
 
80
  .gr-button {
81
  background-color: #007bff !important;
82
  color: white !important;
83
  font-weight: bold;
84
  transition: background-color 0.3s ease;
85
  }
 
86
  .gr-button:hover {
87
  background-color: #0056b3 !important;
88
  }
89
  """
90
 
91
  with gr.Blocks(css=custom_css) as demo:
92
+ gr.Markdown("### πŸ’¬ ChatLoop β€” Talk with Aymaan & Zaid")
93
+
94
  chatbot = gr.Chatbot(label="Chat", height=400, bubble_full_width=False)
95
+ chatbot.render_markdown = False # Allow HTML for alignment and avatar
96
  with gr.Row():
97
+ msg = gr.Textbox(placeholder="Type your message...", show_label=False, lines=1, scale=4)
98
  send_btn = gr.Button("πŸ“¨ Send", scale=1)
99
  clear_btn = gr.Button("🧹 Clear Chat", variant="secondary")
100