3v324v23 commited on
Commit
e79b0c0
1 Parent(s): 730cd1e

提交后不清空输入栏,添加停止键

Browse files
Files changed (1) hide show
  1. main.py +9 -9
main.py CHANGED
@@ -36,7 +36,7 @@ gr.Chatbot.postprocess = format_io
36
  from theme import adjust_theme
37
  set_theme = adjust_theme()
38
 
39
- can_cancel_events = []
40
  with gr.Blocks(theme=set_theme, analytics_enabled=False) as demo:
41
  gr.HTML(title_html)
42
  with gr.Row():
@@ -77,18 +77,18 @@ with gr.Blocks(theme=set_theme, analytics_enabled=False) as demo:
77
  temperature = gr.Slider(minimum=-0, maximum=2.0, value=1.0, step=0.01, interactive=True, label="Temperature",)
78
 
79
  predict_args = dict(fn=predict, inputs=[txt, top_p, temperature, chatbot, history, system_prompt], outputs=[chatbot, history, statusDisplay], show_progress=True)
80
- empty_txt_args = dict(fn=lambda: "", inputs=[], outputs=[txt])
81
 
82
- can_cancel_events.append(txt.submit(**predict_args))
83
- txt.submit(**empty_txt_args)
84
- can_cancel_events.append(submitBtn.click(**predict_args))
85
- submitBtn.click(**empty_txt_args)
86
  resetBtn.click(lambda: ([], [], "已重置"), None, [chatbot, history, statusDisplay])
87
  stopBtn.click(fn=None, inputs=None, outputs=None, cancels=[submit_event])
88
  for k in functional:
89
  click_handle = functional[k]["Button"].click(predict,
90
  [txt, top_p, temperature, chatbot, history, system_prompt, gr.State(True), gr.State(k)], [chatbot, history, statusDisplay], show_progress=True)
91
- can_cancel_events.append(click_handle)
92
  file_upload.upload(on_file_uploaded, [file_upload, chatbot, txt], [chatbot, txt])
93
  for k in crazy_functional:
94
  click_handle = crazy_functional[k]["Button"].click(crazy_functional[k]["Function"],
@@ -96,8 +96,8 @@ with gr.Blocks(theme=set_theme, analytics_enabled=False) as demo:
96
  )
97
  try: click_handle.then(on_report_generated, [file_upload, chatbot], [file_upload, chatbot])
98
  except: pass
99
- can_cancel_events.append(click_handle)
100
- stopBtn.click(fn=None, inputs=None, outputs=None, cancels=can_cancel_events)
101
 
102
  # gradio的inbrowser触发不太稳定,回滚代码到原始的浏览器打开函数
103
  def auto_opentab_delay():
 
36
  from theme import adjust_theme
37
  set_theme = adjust_theme()
38
 
39
+ cancel_handles = []
40
  with gr.Blocks(theme=set_theme, analytics_enabled=False) as demo:
41
  gr.HTML(title_html)
42
  with gr.Row():
 
77
  temperature = gr.Slider(minimum=-0, maximum=2.0, value=1.0, step=0.01, interactive=True, label="Temperature",)
78
 
79
  predict_args = dict(fn=predict, inputs=[txt, top_p, temperature, chatbot, history, system_prompt], outputs=[chatbot, history, statusDisplay], show_progress=True)
80
+ empty_txt_args = dict(fn=lambda: "", inputs=[], outputs=[txt]) # 用于在提交后清空输入栏
81
 
82
+ cancel_handles.append(txt.submit(**predict_args))
83
+ # txt.submit(**empty_txt_args) 在提交后清空输入栏
84
+ cancel_handles.append(submitBtn.click(**predict_args))
85
+ # submitBtn.click(**empty_txt_args) 在提交后清空输入栏
86
  resetBtn.click(lambda: ([], [], "已重置"), None, [chatbot, history, statusDisplay])
87
  stopBtn.click(fn=None, inputs=None, outputs=None, cancels=[submit_event])
88
  for k in functional:
89
  click_handle = functional[k]["Button"].click(predict,
90
  [txt, top_p, temperature, chatbot, history, system_prompt, gr.State(True), gr.State(k)], [chatbot, history, statusDisplay], show_progress=True)
91
+ cancel_handles.append(click_handle)
92
  file_upload.upload(on_file_uploaded, [file_upload, chatbot, txt], [chatbot, txt])
93
  for k in crazy_functional:
94
  click_handle = crazy_functional[k]["Button"].click(crazy_functional[k]["Function"],
 
96
  )
97
  try: click_handle.then(on_report_generated, [file_upload, chatbot], [file_upload, chatbot])
98
  except: pass
99
+ cancel_handles.append(click_handle)
100
+ stopBtn.click(fn=None, inputs=None, outputs=None, cancels=cancel_handles)
101
 
102
  # gradio的inbrowser触发不太稳定,回滚代码到原始的浏览器打开函数
103
  def auto_opentab_delay():