DSDUDEd commited on
Commit
511c788
·
verified ·
1 Parent(s): e13eff9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -7
app.py CHANGED
@@ -5,8 +5,8 @@ import requests
5
  HF_API_URL = "https://api-inference.huggingface.co/models/driaforall/mem-agent"
6
  HF_TOKEN = "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"
7
 
8
- USER_AVATAR = "https://i.imgur.com/YourUserAvatar.png" # replace with your avatar URL
9
- AI_AVATAR = "https://i.imgur.com/YourAIAvatar.png" # replace with AI avatar URL
10
 
11
  GOOGLE_VERIFICATION = "OXT03M7HRqpImYW2myqTjRmEP_f8wZi2SnbrO0JmGcc"
12
 
@@ -20,7 +20,6 @@ def call_ai(message):
20
  try:
21
  response = requests.post(HF_API_URL, headers=headers, json=payload)
22
  data = response.json()
23
- # Parse AI response safely
24
  reply = "⚠️ No response from AI"
25
  if isinstance(data, list) and len(data) > 0:
26
  if "generated_text" in data[0]:
@@ -45,9 +44,11 @@ with gr.Blocks(title="Mem-Agent AI Chat", theme="default") as demo:
45
  """)
46
 
47
  gr.Markdown("## 💬 Mem-Agent AI Chat")
48
-
49
  with gr.Column():
50
- chat_history = gr.Chatbot(elem_id="chatbot").style(height=500)
 
 
51
  with gr.Row():
52
  user_input = gr.Textbox(
53
  placeholder="Type your message here...",
@@ -58,8 +59,8 @@ with gr.Blocks(title="Mem-Agent AI Chat", theme="default") as demo:
58
  # Handle sending messages
59
  def respond(message, chat):
60
  ai_reply = call_ai(message)
61
- chat.append((f'<img src="{USER_AVATAR}" width="40"/> {message}',
62
- f'<img src="{AI_AVATAR}" width="40"/> {ai_reply}'))
63
  return "", chat
64
 
65
  submit_btn.click(respond, [user_input, chat_history], [user_input, chat_history])
 
5
  HF_API_URL = "https://api-inference.huggingface.co/models/driaforall/mem-agent"
6
  HF_TOKEN = "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"
7
 
8
+ USER_AVATAR = "https://i.imgur.com/YourUserAvatar.png"
9
+ AI_AVATAR = "https://i.imgur.com/YourAIAvatar.png"
10
 
11
  GOOGLE_VERIFICATION = "OXT03M7HRqpImYW2myqTjRmEP_f8wZi2SnbrO0JmGcc"
12
 
 
20
  try:
21
  response = requests.post(HF_API_URL, headers=headers, json=payload)
22
  data = response.json()
 
23
  reply = "⚠️ No response from AI"
24
  if isinstance(data, list) and len(data) > 0:
25
  if "generated_text" in data[0]:
 
44
  """)
45
 
46
  gr.Markdown("## 💬 Mem-Agent AI Chat")
47
+
48
  with gr.Column():
49
+ # Updated for modern Gradio
50
+ chat_history = gr.Chatbot(elem_id="chatbot", type="messages")
51
+
52
  with gr.Row():
53
  user_input = gr.Textbox(
54
  placeholder="Type your message here...",
 
59
  # Handle sending messages
60
  def respond(message, chat):
61
  ai_reply = call_ai(message)
62
+ chat.append({"role": "user", "content": f"{message}"})
63
+ chat.append({"role": "assistant", "content": f"{ai_reply}"})
64
  return "", chat
65
 
66
  submit_btn.click(respond, [user_input, chat_history], [user_input, chat_history])