From 3d27b4dc9008572b461775c943b3fcf3d77c1f11 Mon Sep 17 00:00:00 2001 From: Keldos Date: Thu, 19 Sep 2024 20:05:54 +0800 Subject: [PATCH] refactor: rebind download button --- ChuanhuChatbot.py | 15 ++++----------- web_assets/javascript/fake-gradio.js | 7 ++----- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/ChuanhuChatbot.py b/ChuanhuChatbot.py index 90101e72..29101c84 100644 --- a/ChuanhuChatbot.py +++ b/ChuanhuChatbot.py @@ -100,8 +100,10 @@ def create_new_model(): with gr.Column(scale=1): renameHistoryBtn = gr.Button( i18n("💾 保存对话"), elem_id="gr-history-save-btn") - exportMarkdownBtn = gr.Button( - i18n("📝 导出为 Markdown"), elem_id="gr-markdown-export-btn") + downloadHistoryJSONBtn = gr.DownloadButton( + i18n("历史记录(JSON)"), elem_id="gr-history-download-json-btn") + downloadHistoryMarkdownBtn = gr.DownloadButton( + i18n("导出为 Markdown"), elem_id="gr-history-download-md-btn") with gr.Column(elem_id="chuanhu-menu-footer"): with gr.Row(elem_id="chuanhu-func-nav"): @@ -120,9 +122,6 @@ def create_new_model(): label=i18n("选择模型"), choices=[], multiselect=False, interactive=True, visible=False, container=False, ) - # with gr.Column(min_width=150, scale=1, elem_id="chatbot-header-btn-bar"): - downloadHistoryJSONBtn = gr.DownloadButton(i18n("历史记录(JSON)")) - downloadHistoryMarkdownBtn = gr.DownloadButton(i18n("导出为 Markdown")) gr.HTML(get_html("chatbot_header_btn.html").format( json_label=i18n("历史记录(JSON)"), md_label=i18n("导出为 Markdown") @@ -690,12 +689,6 @@ def create_greeting(request: gr.Request): show_progress=True, js='(a,b,c,d)=>{return saveChatHistory(a,b,c,d);}' ) - exportMarkdownBtn.click( - export_markdown, - [current_model, saveFileName, chatbot], - [], - show_progress=True, - ) historyRefreshBtn.click(**refresh_history_args) historyDeleteBtn.click(delete_chat_history, [current_model, historySelectList], [status_display, historySelectList, chatbot], js='(a,b,c)=>{return showConfirmationDialog(a, b, c);}').then( reset, diff --git a/web_assets/javascript/fake-gradio.js b/web_assets/javascript/fake-gradio.js index 5a24dc71..c8c3a2c2 100644 --- a/web_assets/javascript/fake-gradio.js +++ b/web_assets/javascript/fake-gradio.js @@ -6,13 +6,10 @@ function newChatClick() { gradioApp().querySelector('#empty-btn').click(); } function jsonDownloadClick() { - gradioApp().querySelector('#gr-history-download-btn').click(); + gradioApp().querySelector('#gr-history-download-json-btn').click(); } function mdDownloadClick() { - gradioApp().querySelector('#gr-markdown-export-btn').click(); - gradioApp().querySelector('#gr-history-mardown-download-btn').click(); - - // downloadHistory(username, currentChatName, ".md"); + gradioApp().querySelector('#gr-history-download-md-btn').click(); } // index files