trinhhuy commited on
Commit
21a4f65
·
verified ·
1 Parent(s): 3bade4c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -12
app.py CHANGED
@@ -4,18 +4,11 @@ import agent
4
 
5
  # --------- Hàm xử lý chat ----------
6
  def respond(user_message, chat_history):
7
- if not user_message:
8
  return chat_history, gr.update(value="")
9
-
10
- # Thêm tin nhắn user
11
- chat_history.append({"role": "user", "content": user_message})
12
-
13
- # Lấy phản hồi từ agent
14
- bot_reply = agent.chat_with_agent(user_message)
15
-
16
- # Thêm tin nhắn bot
17
- chat_history.append({"role": "assistant", "content": bot_reply})
18
-
19
  return chat_history, gr.update(value="")
20
 
21
  def clear_chat():
@@ -37,7 +30,6 @@ with gr.Blocks(theme=gr.themes.Default()) as demo:
37
 
38
 
39
  chatbot = gr.Chatbot(
40
- type="messages",
41
  label="Chatbot",
42
  height=420,
43
  # show_copy_button=True, # cho phép copy nội dung nhanh
 
4
 
5
  # --------- Hàm xử lý chat ----------
6
  def respond(user_message, chat_history):
7
+ if not user_message or not user_message:
8
  return chat_history, gr.update(value="")
9
+ user_bubble = f"{user_message}🧑"
10
+ bot_reply = f"🤖 {agent.chat_with_agent(user_message)}"
11
+ chat_history = chat_history + [(user_bubble, bot_reply)]
 
 
 
 
 
 
 
12
  return chat_history, gr.update(value="")
13
 
14
  def clear_chat():
 
30
 
31
 
32
  chatbot = gr.Chatbot(
 
33
  label="Chatbot",
34
  height=420,
35
  # show_copy_button=True, # cho phép copy nội dung nhanh