ysharma HF staff commited on
Commit
a3c927c
1 Parent(s): af96a70

added delete last turn button and logic

Browse files

added the button, the click event and the inference function for deleting the last turn

Files changed (1) hide show
  1. app.py +9 -1
app.py CHANGED
@@ -192,7 +192,13 @@ examples = [
192
  def clear_chat():
193
  return [], []
194
 
195
-
 
 
 
 
 
 
196
  def process_example(args):
197
  for [x, y] in generate(args):
198
  pass
@@ -262,6 +268,7 @@ with gr.Blocks(analytics_enabled=False, css=custom_css) as demo:
262
  send_button = gr.Button("Send", elem_id="send-btn", visible=True)
263
 
264
  # regenerate_button = gr.Button("Regenerate", elem_id="send-btn", visible=True)
 
265
 
266
  clear_chat_button = gr.Button("Clear chat", elem_id="clear-btn", visible=True)
267
 
@@ -364,6 +371,7 @@ with gr.Blocks(analytics_enabled=False, css=custom_css) as demo:
364
  outputs=[chatbot, history, last_user_message, user_message],
365
  )
366
 
 
367
  clear_chat_button.click(clear_chat, outputs=[chatbot, history])
368
  selected_model.change(clear_chat, outputs=[chatbot, history])
369
  # share_button.click(None, [], [], _js=share_js)
 
192
  def clear_chat():
193
  return [], []
194
 
195
+ def delete_last_turn(chat, history):
196
+ if chat and history:
197
+ chat.pop(-1)
198
+ history.pop(-1)
199
+ history.pop(-1)
200
+ return chat, history
201
+
202
  def process_example(args):
203
  for [x, y] in generate(args):
204
  pass
 
268
  send_button = gr.Button("Send", elem_id="send-btn", visible=True)
269
 
270
  # regenerate_button = gr.Button("Regenerate", elem_id="send-btn", visible=True)
271
+ delete_turn_button = gr.Button("Delete last turn", elem_id="delete-btn", visible=True)
272
 
273
  clear_chat_button = gr.Button("Clear chat", elem_id="clear-btn", visible=True)
274
 
 
371
  outputs=[chatbot, history, last_user_message, user_message],
372
  )
373
 
374
+ delete_turn_button.click(delete_last_turn, [chatbot, history], [chatbot, history])
375
  clear_chat_button.click(clear_chat, outputs=[chatbot, history])
376
  selected_model.change(clear_chat, outputs=[chatbot, history])
377
  # share_button.click(None, [], [], _js=share_js)