0Learn commited on
Commit
ae92619
Β·
verified Β·
1 Parent(s): 5aa8708

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -11
app.py CHANGED
@@ -22,15 +22,15 @@ def get_bot_response(message):
22
  def chat(message, history):
23
  history = history or []
24
  # Add user message to chat history
25
- history.append({"role": "user", "content": message})
26
 
27
  # Get bot response
28
  bot_message = get_bot_response(message)
29
 
30
  # Add bot message to chat history
31
- history.append({"role": "assistant", "content": bot_message})
32
 
33
- return history, history
34
 
35
  # Function to add selected emoji to input
36
  def add_emoji(emoji, current_input):
@@ -38,14 +38,14 @@ def add_emoji(emoji, current_input):
38
 
39
  # Function to copy the last bot message
40
  def copy_last_message(history):
41
- if history and history[-1]["role"] == "assistant":
42
- return history[-1]["content"]
43
  return "No message to copy."
44
 
45
  # Function to handle feedback
46
  def handle_feedback(feedback, history):
47
  if history:
48
- last_message = history[-1]["content"]
49
  print(f"Feedback for '{last_message}': {feedback}")
50
  return history
51
 
@@ -54,9 +54,9 @@ with gr.Blocks() as demo:
54
  chatbot = gr.Chatbot()
55
 
56
  with gr.Row():
57
- with gr.Column(scale=0.9):
58
  msg = gr.Textbox(label="Type your message here", placeholder="Enter your message...")
59
- with gr.Column(scale=0.1):
60
  emoji_dropdown = gr.Dropdown(choices=emojis, label="", interactive=True)
61
 
62
  with gr.Row():
@@ -71,9 +71,9 @@ with gr.Blocks() as demo:
71
  thumbs_down = gr.Button("πŸ‘Ž")
72
 
73
  # Set up event handlers
74
- submit.click(chat, inputs=[msg, chatbot], outputs=[chatbot, chatbot])
75
- msg.submit(chat, inputs=[msg, chatbot], outputs=[chatbot, chatbot])
76
- clear.click(lambda: [], None, chatbot, queue=False)
77
  emoji_dropdown.change(add_emoji, inputs=[emoji_dropdown, msg], outputs=msg)
78
  copy_button.click(copy_last_message, inputs=[chatbot], outputs=[copied_text])
79
  thumbs_up.click(handle_feedback, inputs=["thumbs up", chatbot], outputs=[chatbot])
 
22
  def chat(message, history):
23
  history = history or []
24
  # Add user message to chat history
25
+ history.append((message, ""))
26
 
27
  # Get bot response
28
  bot_message = get_bot_response(message)
29
 
30
  # Add bot message to chat history
31
+ history[-1] = (message, bot_message)
32
 
33
+ return history
34
 
35
  # Function to add selected emoji to input
36
  def add_emoji(emoji, current_input):
 
38
 
39
  # Function to copy the last bot message
40
  def copy_last_message(history):
41
+ if history and history[-1][1]:
42
+ return history[-1][1]
43
  return "No message to copy."
44
 
45
  # Function to handle feedback
46
  def handle_feedback(feedback, history):
47
  if history:
48
+ last_message = history[-1][1]
49
  print(f"Feedback for '{last_message}': {feedback}")
50
  return history
51
 
 
54
  chatbot = gr.Chatbot()
55
 
56
  with gr.Row():
57
+ with gr.Column(scale=9):
58
  msg = gr.Textbox(label="Type your message here", placeholder="Enter your message...")
59
+ with gr.Column(scale=1):
60
  emoji_dropdown = gr.Dropdown(choices=emojis, label="", interactive=True)
61
 
62
  with gr.Row():
 
71
  thumbs_down = gr.Button("πŸ‘Ž")
72
 
73
  # Set up event handlers
74
+ submit.click(chat, inputs=[msg, chatbot], outputs=[chatbot])
75
+ msg.submit(chat, inputs=[msg, chatbot], outputs=[chatbot])
76
+ clear.click(lambda: None, None, chatbot, queue=False)
77
  emoji_dropdown.change(add_emoji, inputs=[emoji_dropdown, msg], outputs=msg)
78
  copy_button.click(copy_last_message, inputs=[chatbot], outputs=[copied_text])
79
  thumbs_up.click(handle_feedback, inputs=["thumbs up", chatbot], outputs=[chatbot])