Просмотр исходного кода

Add "remove last message" button to chat

oobabooga 3 лет назад
Родитель
Сommit
13b04c1b94
1 измененных файлов с 10 добавлено и 1 удалено
  1. 10 1
      server.py

+ 10 - 1
server.py

@@ -223,6 +223,10 @@ elif args.chat:
         history.append((text, reply))
         return history
 
+    def remove_last_message():
+        history.pop()
+        return history
+
     def clear():
         global history
         history = []
@@ -257,10 +261,15 @@ elif args.chat:
                 display1 = gr.Chatbot()
                 textbox = gr.Textbox(lines=2, label='Input')
                 btn = gr.Button("Generate")
-                btn2 = gr.Button("Clear history")
+                with gr.Row():
+                    with gr.Column():
+                        btn3 = gr.Button("Remove last message")
+                    with gr.Column():
+                        btn2 = gr.Button("Clear history")
 
         btn.click(chatbot_wrapper, [textbox, length_slider, preset_menu, model_menu, name1, name2, context, check], display1, show_progress=True, api_name="textgen")
         textbox.submit(chatbot_wrapper, [textbox, length_slider, preset_menu, model_menu, name1, name2, context, check], display1, show_progress=True)
+        btn3.click(remove_last_message, [], display1, show_progress=False)
         btn2.click(clear)
         btn.click(lambda x: "", textbox, textbox, show_progress=False)
         textbox.submit(lambda x: "", textbox, textbox, show_progress=False)