Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,76 +1,75 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import json
|
| 3 |
-
import os
|
| 4 |
from agents.programmer import ProgrammerAgent
|
| 5 |
from agents.debugger import DebuggerAgent
|
| 6 |
from agents.base_agent import ACPMessage
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
#
|
| 9 |
aymaan = ProgrammerAgent()
|
| 10 |
zaid = DebuggerAgent()
|
|
|
|
|
|
|
| 11 |
chat_memory = []
|
| 12 |
|
| 13 |
-
#
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
print(f"Error loading prompts: {e}")
|
| 20 |
-
return []
|
| 21 |
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
# === Main Chat Handler ===
|
| 25 |
def chat(user_input):
|
| 26 |
if not user_input.strip():
|
| 27 |
return chat_memory
|
| 28 |
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
response_zaid = zaid.create_message("User", "inform", "Hi hi! π How can I assist you today?")
|
| 35 |
else:
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
chat_memory.append({"role": "user", "content": user_input})
|
| 40 |
-
chat_memory.append({"role": "
|
| 41 |
-
chat_memory.append({"role": "
|
| 42 |
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
-
# === Memory Reset ===
|
| 46 |
def reset_memory():
|
| 47 |
global chat_memory
|
| 48 |
chat_memory = []
|
| 49 |
-
return
|
| 50 |
|
| 51 |
-
# === App UI ===
|
| 52 |
with gr.Blocks(css="footer {margin-top: 2em; text-align: center;}") as demo:
|
| 53 |
-
gr.Markdown("## π€ BotTalks
|
| 54 |
-
|
| 55 |
-
chatbot = gr.Chatbot(label="Group Chat", type="messages", height=300)
|
| 56 |
-
msg = gr.Textbox(label="You", placeholder="Ask anything...")
|
| 57 |
-
send_btn = gr.Button("π€ Send")
|
| 58 |
-
clear_btn = gr.Button("π§Ή Reset Memory")
|
| 59 |
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
|
|
|
| 63 |
|
| 64 |
send_btn.click(chat, inputs=msg, outputs=chatbot)
|
| 65 |
clear_btn.click(reset_memory, outputs=chatbot)
|
| 66 |
|
| 67 |
gr.HTML("""
|
| 68 |
<footer>
|
| 69 |
-
|
| 70 |
-
<a href="https://www.linkedin.com/in/aymnsk" target="_blank">LinkedIn</a> |
|
| 71 |
-
<a href="https://github.com/aymnsk" target="_blank">GitHub</a> |
|
| 72 |
-
<a href="https://www.instagram.com/damnn_aymn/" target="_blank">Instagram</a> |
|
| 73 |
-
<a href="https://huggingface.co/aymnsk" target="_blank">HF</a>
|
| 74 |
</footer>
|
| 75 |
""")
|
| 76 |
|
|
|
|
| 1 |
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
|
| 9 |
aymaan = ProgrammerAgent()
|
| 10 |
zaid = DebuggerAgent()
|
| 11 |
+
|
| 12 |
+
# In-memory chat
|
| 13 |
chat_memory = []
|
| 14 |
|
| 15 |
+
# Load greeting shortcut mappings (optional JSON file)
|
| 16 |
+
GREETING_RESPONSES = {
|
| 17 |
+
"hi": "Hey there! π",
|
| 18 |
+
"hello": "Hello! How can I help?",
|
| 19 |
+
"how are you": "Doing great! Thanks for asking π",
|
| 20 |
+
}
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
def fast_greeting_handler(msg):
|
| 23 |
+
lowered = msg.lower()
|
| 24 |
+
for greeting in GREETING_RESPONSES:
|
| 25 |
+
if greeting in lowered:
|
| 26 |
+
return True, GREETING_RESPONSES[greeting]
|
| 27 |
+
return False, ""
|
| 28 |
|
|
|
|
| 29 |
def chat(user_input):
|
| 30 |
if not user_input.strip():
|
| 31 |
return chat_memory
|
| 32 |
|
| 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": "user", "content": user_input})
|
| 46 |
+
chat_memory.append({"role": "Aymaan", "content": response_aymaan})
|
| 47 |
+
chat_memory.append({"role": "Zaid", "content": response_zaid})
|
| 48 |
|
| 49 |
+
formatted = []
|
| 50 |
+
for item in chat_memory:
|
| 51 |
+
formatted.append((item["role"], item["content"]))
|
| 52 |
+
return formatted
|
| 53 |
|
|
|
|
| 54 |
def reset_memory():
|
| 55 |
global chat_memory
|
| 56 |
chat_memory = []
|
| 57 |
+
return []
|
| 58 |
|
|
|
|
| 59 |
with gr.Blocks(css="footer {margin-top: 2em; text-align: center;}") as demo:
|
| 60 |
+
gr.Markdown("## π€ BotTalks (Groq Edition) β Chat with Aymaan & Zaid")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
+
chatbot = gr.Chatbot(label="Group Chat", height=300)
|
| 63 |
+
msg = gr.Textbox(label="Type your message...")
|
| 64 |
+
send_btn = gr.Button("Send")
|
| 65 |
+
clear_btn = gr.Button("π§Ή Clear Chat")
|
| 66 |
|
| 67 |
send_btn.click(chat, inputs=msg, outputs=chatbot)
|
| 68 |
clear_btn.click(reset_memory, outputs=chatbot)
|
| 69 |
|
| 70 |
gr.HTML("""
|
| 71 |
<footer>
|
| 72 |
+
π¨βπ» Made by <a href="https://github.com/aymnsk" target="_blank">aymnsk</a> β’ Powered by <a href="https://groq.com/" target="_blank">Groq API</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
</footer>
|
| 74 |
""")
|
| 75 |
|