commit
cbcdd39239
@ -20,7 +20,7 @@ else:
|
|||||||
print('网络代理状态:未配置。无代理状态下很可能无法访问。')
|
print('网络代理状态:未配置。无代理状态下很可能无法访问。')
|
||||||
|
|
||||||
# 发送请求到OpenAI后,等待多久判定为超时
|
# 发送请求到OpenAI后,等待多久判定为超时
|
||||||
TIMEOUT_SECONDS = 20
|
TIMEOUT_SECONDS = 25
|
||||||
|
|
||||||
# 网页的端口, -1代表随机端口
|
# 网页的端口, -1代表随机端口
|
||||||
WEB_PORT = -1
|
WEB_PORT = -1
|
||||||
|
18
main.py
18
main.py
@ -36,6 +36,7 @@ gr.Chatbot.postprocess = format_io
|
|||||||
from theme import adjust_theme
|
from theme import adjust_theme
|
||||||
set_theme = adjust_theme()
|
set_theme = adjust_theme()
|
||||||
|
|
||||||
|
cancel_handles = []
|
||||||
with gr.Blocks(theme=set_theme, analytics_enabled=False) as demo:
|
with gr.Blocks(theme=set_theme, analytics_enabled=False) as demo:
|
||||||
gr.HTML(title_html)
|
gr.HTML(title_html)
|
||||||
with gr.Row():
|
with gr.Row():
|
||||||
@ -52,6 +53,7 @@ with gr.Blocks(theme=set_theme, analytics_enabled=False) as demo:
|
|||||||
with gr.Row():
|
with gr.Row():
|
||||||
resetBtn = gr.Button("重置", variant="secondary")
|
resetBtn = gr.Button("重置", variant="secondary")
|
||||||
submitBtn = gr.Button("提交", variant="primary")
|
submitBtn = gr.Button("提交", variant="primary")
|
||||||
|
stopBtn = gr.Button("停止", variant="stop")
|
||||||
with gr.Row():
|
with gr.Row():
|
||||||
from check_proxy import check_proxy
|
from check_proxy import check_proxy
|
||||||
statusDisplay = gr.Markdown(f"Tip: 按Enter提交, 按Shift+Enter换行. \nNetwork: {check_proxy(proxies)}\nModel: {LLM_MODEL}")
|
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:
|
|||||||
temperature = gr.Slider(minimum=-0, maximum=2.0, value=1.0, step=0.01, interactive=True, label="Temperature",)
|
temperature = gr.Slider(minimum=-0, maximum=2.0, value=1.0, step=0.01, interactive=True, label="Temperature",)
|
||||||
|
|
||||||
predict_args = dict(fn=predict, inputs=[txt, top_p, temperature, chatbot, history, system_prompt], outputs=[chatbot, history, statusDisplay], show_progress=True)
|
predict_args = dict(fn=predict, inputs=[txt, top_p, temperature, chatbot, history, system_prompt], outputs=[chatbot, history, statusDisplay], show_progress=True)
|
||||||
empty_txt_args = dict(fn=lambda: "", inputs=[], outputs=[txt])
|
empty_txt_args = dict(fn=lambda: "", inputs=[], outputs=[txt]) # 用于在提交后清空输入栏
|
||||||
|
|
||||||
txt.submit(**predict_args)
|
cancel_handles.append(txt.submit(**predict_args))
|
||||||
txt.submit(**empty_txt_args)
|
# txt.submit(**empty_txt_args) 在提交后清空输入栏
|
||||||
submitBtn.click(**predict_args)
|
cancel_handles.append(submitBtn.click(**predict_args))
|
||||||
submitBtn.click(**empty_txt_args)
|
# submitBtn.click(**empty_txt_args) 在提交后清空输入栏
|
||||||
resetBtn.click(lambda: ([], [], "已重置"), None, [chatbot, history, statusDisplay])
|
resetBtn.click(lambda: ([], [], "已重置"), None, [chatbot, history, statusDisplay])
|
||||||
|
stopBtn.click(fn=None, inputs=None, outputs=None, cancels=[submit_event])
|
||||||
for k in functional:
|
for k in functional:
|
||||||
functional[k]["Button"].click(predict,
|
click_handle = functional[k]["Button"].click(predict,
|
||||||
[txt, top_p, temperature, chatbot, history, system_prompt, gr.State(True), gr.State(k)], [chatbot, history, statusDisplay], show_progress=True)
|
[txt, top_p, temperature, chatbot, history, system_prompt, gr.State(True), gr.State(k)], [chatbot, history, statusDisplay], show_progress=True)
|
||||||
|
cancel_handles.append(click_handle)
|
||||||
file_upload.upload(on_file_uploaded, [file_upload, chatbot, txt], [chatbot, txt])
|
file_upload.upload(on_file_uploaded, [file_upload, chatbot, txt], [chatbot, txt])
|
||||||
for k in crazy_functional:
|
for k in crazy_functional:
|
||||||
click_handle = crazy_functional[k]["Button"].click(crazy_functional[k]["Function"],
|
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:
|
|||||||
)
|
)
|
||||||
try: click_handle.then(on_report_generated, [file_upload, chatbot], [file_upload, chatbot])
|
try: click_handle.then(on_report_generated, [file_upload, chatbot], [file_upload, chatbot])
|
||||||
except: pass
|
except: pass
|
||||||
|
cancel_handles.append(click_handle)
|
||||||
|
stopBtn.click(fn=None, inputs=None, outputs=None, cancels=cancel_handles)
|
||||||
|
|
||||||
# gradio的inbrowser触发不太稳定,回滚代码到原始的浏览器打开函数
|
# gradio的inbrowser触发不太稳定,回滚代码到原始的浏览器打开函数
|
||||||
def auto_opentab_delay():
|
def auto_opentab_delay():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user