binary-husky commited on
Commit
cbcdd39
2 Parent(s): 23776b9 e79b0c0

Merge pull request #82 from Okabe-Rintarou-0/master

Browse files
Files changed (2) hide show
  1. config.py +1 -1
  2. main.py +12 -6
config.py CHANGED
@@ -20,7 +20,7 @@ else:
20
  print('网络代理状态:未配置。无代理状态下很可能无法访问。')
21
 
22
  # 发送请求到OpenAI后,等待多久判定为超时
23
- TIMEOUT_SECONDS = 20
24
 
25
  # 网页的端口, -1代表随机端口
26
  WEB_PORT = -1
 
20
  print('网络代理状态:未配置。无代理状态下很可能无法访问。')
21
 
22
  # 发送请求到OpenAI后,等待多久判定为超时
23
+ TIMEOUT_SECONDS = 25
24
 
25
  # 网页的端口, -1代表随机端口
26
  WEB_PORT = -1
main.py CHANGED
@@ -36,6 +36,7 @@ gr.Chatbot.postprocess = format_io
36
  from theme import adjust_theme
37
  set_theme = adjust_theme()
38
 
 
39
  with gr.Blocks(theme=set_theme, analytics_enabled=False) as demo:
40
  gr.HTML(title_html)
41
  with gr.Row():
@@ -52,6 +53,7 @@ with gr.Blocks(theme=set_theme, analytics_enabled=False) as demo:
52
  with gr.Row():
53
  resetBtn = gr.Button("重置", variant="secondary")
54
  submitBtn = gr.Button("提交", variant="primary")
 
55
  with gr.Row():
56
  from check_proxy import check_proxy
57
  statusDisplay = gr.Markdown(f"Tip: 按Enter提交, 按Shift+Enter换行. \nNetwork: {check_proxy(proxies)}\nModel: {LLM_MODEL}")
@@ -75,16 +77,18 @@ with gr.Blocks(theme=set_theme, analytics_enabled=False) as demo:
75
  temperature = gr.Slider(minimum=-0, maximum=2.0, value=1.0, step=0.01, interactive=True, label="Temperature",)
76
 
77
  predict_args = dict(fn=predict, inputs=[txt, top_p, temperature, chatbot, history, system_prompt], outputs=[chatbot, history, statusDisplay], show_progress=True)
78
- empty_txt_args = dict(fn=lambda: "", inputs=[], outputs=[txt])
79
 
80
- txt.submit(**predict_args)
81
- txt.submit(**empty_txt_args)
82
- submitBtn.click(**predict_args)
83
- submitBtn.click(**empty_txt_args)
84
  resetBtn.click(lambda: ([], [], "已重置"), None, [chatbot, history, statusDisplay])
 
85
  for k in functional:
86
- functional[k]["Button"].click(predict,
87
  [txt, top_p, temperature, chatbot, history, system_prompt, gr.State(True), gr.State(k)], [chatbot, history, statusDisplay], show_progress=True)
 
88
  file_upload.upload(on_file_uploaded, [file_upload, chatbot, txt], [chatbot, txt])
89
  for k in crazy_functional:
90
  click_handle = crazy_functional[k]["Button"].click(crazy_functional[k]["Function"],
@@ -92,6 +96,8 @@ with gr.Blocks(theme=set_theme, analytics_enabled=False) as demo:
92
  )
93
  try: click_handle.then(on_report_generated, [file_upload, chatbot], [file_upload, chatbot])
94
  except: pass
 
 
95
 
96
  # gradio的inbrowser触发不太稳定,回滚代码到原始的浏览器打开函数
97
  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():
 
53
  with gr.Row():
54
  resetBtn = gr.Button("重置", variant="secondary")
55
  submitBtn = gr.Button("提交", variant="primary")
56
+ stopBtn = gr.Button("停止", variant="stop")
57
  with gr.Row():
58
  from check_proxy import check_proxy
59
  statusDisplay = gr.Markdown(f"Tip: 按Enter提交, 按Shift+Enter换行. \nNetwork: {check_proxy(proxies)}\nModel: {LLM_MODEL}")
 
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():