From e2903171468212041c9881a7dd255389a975acc1 Mon Sep 17 00:00:00 2001 From: binary-husky Date: Mon, 15 Jul 2024 03:28:59 +0000 Subject: [PATCH] proxy submit btn --- main.py | 17 +++++++---------- themes/common.js | 5 +++++ themes/gui_floating_menu.py | 2 ++ themes/mermaid.min.js | 1 - themes/mermaid_editor.js | 1 - themes/mermaid_loader.js | 1 - themes/pako.esm.mjs | 1 - themes/sovits_audio.js | 0 8 files changed, 14 insertions(+), 14 deletions(-) delete mode 100644 themes/mermaid.min.js delete mode 100644 themes/mermaid_editor.js delete mode 100644 themes/mermaid_loader.js delete mode 100644 themes/pako.esm.mjs delete mode 100644 themes/sovits_audio.js diff --git a/main.py b/main.py index 0ad79b78..3feebbb2 100644 --- a/main.py +++ b/main.py @@ -112,8 +112,11 @@ def main(): with gr.Accordion("输入区", open=True, elem_id="input-panel") as area_input_primary: with gr.Row(): txt = gr.Textbox(show_label=False, placeholder="Input question here.", elem_id='user_input_main').style(container=False) + txt.submit(None, None, None, _js="""click_real_submit_btn""") with gr.Row(): - submitBtn = gr.Button("提交", elem_id="elem_submit", variant="primary") + advanced_submit_btn = gr.Button("提交", elem_id="elem_submit_fake_1", variant="primary") + advanced_submit_btn.click(None, None, None, _js="""click_real_submit_btn""") + submit_btn = gr.Button("提交", elem_id="elem_submit", variant="primary", visible=False) with gr.Row(): resetBtn = gr.Button("重置", elem_id="elem_reset", variant="secondary"); resetBtn.style(size="sm") stopBtn = gr.Button("停止", elem_id="elem_stop", variant="secondary"); stopBtn.style(size="sm") @@ -177,7 +180,7 @@ def main(): # 浮动菜单定义 from themes.gui_floating_menu import define_gui_floating_menu - area_input_secondary, txt2, area_customize, submitBtn2, resetBtn2, clearBtn2, stopBtn2 = \ + area_input_secondary, txt2, area_customize, _, resetBtn2, clearBtn2, stopBtn2 = \ define_gui_floating_menu(customize_btns, functional, predefined_btns, cookies, web_cookie_cache) # 插件二级菜单的实现 @@ -210,10 +213,7 @@ def main(): output_combo = [cookies, chatbot, history, status] predict_args = dict(fn=ArgsGeneralWrapper(predict), inputs=[*input_combo, gr.State(True)], outputs=output_combo) # 提交按钮、重置按钮 - cancel_handles.append(txt.submit(**predict_args)) - cancel_handles.append(txt2.submit(**predict_args)) - cancel_handles.append(submitBtn.click(**predict_args)) - cancel_handles.append(submitBtn2.click(**predict_args)) + cancel_handles.append(submit_btn.click(**predict_args)) resetBtn.click(None, None, [chatbot, history, status], _js=js_code_reset) # 先在前端快速清除chatbot&status resetBtn2.click(None, None, [chatbot, history, status], _js=js_code_reset) # 先在前端快速清除chatbot&status reset_server_side_args = (lambda history: ([], [], "已重置", json.dumps(history)), [history], [chatbot, history, status, history_cache]) @@ -222,10 +222,7 @@ def main(): clearBtn.click(None, None, [txt, txt2], _js=js_code_clear) clearBtn2.click(None, None, [txt, txt2], _js=js_code_clear) if AUTO_CLEAR_TXT: - submitBtn.click(None, None, [txt, txt2], _js=js_code_clear) - submitBtn2.click(None, None, [txt, txt2], _js=js_code_clear) - txt.submit(None, None, [txt, txt2], _js=js_code_clear) - txt2.submit(None, None, [txt, txt2], _js=js_code_clear) + submit_btn.click(None, None, [txt, txt2], _js=js_code_clear) # 基础功能区的回调函数注册 for k in functional: if ("Visible" in functional[k]) and (not functional[k]["Visible"]): continue diff --git a/themes/common.js b/themes/common.js index 34351f08..af48b375 100644 --- a/themes/common.js +++ b/themes/common.js @@ -1671,3 +1671,8 @@ async function run_classic_plugin_via_id(plugin_elem_id){ // console.log('unable to find function'); return; } + + +async function click_real_submit_btn() { + document.getElementById("elem_submit").click(); +} \ No newline at end of file diff --git a/themes/gui_floating_menu.py b/themes/gui_floating_menu.py index 003141f3..90947c5d 100644 --- a/themes/gui_floating_menu.py +++ b/themes/gui_floating_menu.py @@ -8,8 +8,10 @@ def define_gui_floating_menu(customize_btns, functional, predefined_btns, cookie with gr.Column(scale=10): txt2 = gr.Textbox(show_label=False, placeholder="Input question here.", elem_id='user_input_float', lines=8, label="输入区2").style(container=False) + txt2.submit(None, None, None, _js="""click_real_submit_btn""") with gr.Column(scale=1, min_width=40): submitBtn2 = gr.Button("提交", variant="primary"); submitBtn2.style(size="sm") + submitBtn2.click(None, None, None, _js="""click_real_submit_btn""") resetBtn2 = gr.Button("重置", variant="secondary"); resetBtn2.style(size="sm") stopBtn2 = gr.Button("停止", variant="secondary"); stopBtn2.style(size="sm") clearBtn2 = gr.Button("清除", elem_id="elem_clear2", variant="secondary", visible=False); clearBtn2.style(size="sm") diff --git a/themes/mermaid.min.js b/themes/mermaid.min.js deleted file mode 100644 index b842822b..00000000 --- a/themes/mermaid.min.js +++ /dev/null @@ -1 +0,0 @@ -// we have moved mermaid-related code to gradio-fix repository: binary-husky/gradio-fix@32150d0 diff --git a/themes/mermaid_editor.js b/themes/mermaid_editor.js deleted file mode 100644 index b842822b..00000000 --- a/themes/mermaid_editor.js +++ /dev/null @@ -1 +0,0 @@ -// we have moved mermaid-related code to gradio-fix repository: binary-husky/gradio-fix@32150d0 diff --git a/themes/mermaid_loader.js b/themes/mermaid_loader.js deleted file mode 100644 index b842822b..00000000 --- a/themes/mermaid_loader.js +++ /dev/null @@ -1 +0,0 @@ -// we have moved mermaid-related code to gradio-fix repository: binary-husky/gradio-fix@32150d0 diff --git a/themes/pako.esm.mjs b/themes/pako.esm.mjs deleted file mode 100644 index b842822b..00000000 --- a/themes/pako.esm.mjs +++ /dev/null @@ -1 +0,0 @@ -// we have moved mermaid-related code to gradio-fix repository: binary-husky/gradio-fix@32150d0 diff --git a/themes/sovits_audio.js b/themes/sovits_audio.js deleted file mode 100644 index e69de29b..00000000