Spaces:
Sleeping
Sleeping
Keldos
commited on
Commit
·
d0862ed
1
Parent(s):
578e872
refactor: gradio中执行的js改为引用custom.js
Browse files改了两处:
- 清除对话历史的confirm改为customjs中的函数;
- 改了新的对话时清除仅供查看历史记录的js写法,更简洁了。
- ChuanhuChatbot.py +2 -9
- assets/custom.js +10 -10
ChuanhuChatbot.py
CHANGED
|
@@ -348,6 +348,7 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
|
|
| 348 |
inputs=[current_model],
|
| 349 |
outputs=[chatbot, status_display],
|
| 350 |
show_progress=True,
|
|
|
|
| 351 |
)
|
| 352 |
|
| 353 |
retryBtn.click(**start_outputing_args).then(
|
|
@@ -433,15 +434,7 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
|
|
| 433 |
show_progress=True,
|
| 434 |
)
|
| 435 |
historyRefreshBtn.click(**refresh_history_args)
|
| 436 |
-
historyDeleteBtn.click(delete_chat_history, [current_model, historyFileSelectDropdown, user_name], [status_display, historyFileSelectDropdown, chatbot], _js='
|
| 437 |
-
if (b != "") {
|
| 438 |
-
var result = confirm(deleteConfirm_msg_pref + b + deleteConfirm_msg_suff);
|
| 439 |
-
if (result) {
|
| 440 |
-
return [a, b, c];
|
| 441 |
-
}
|
| 442 |
-
}
|
| 443 |
-
return [a, "CANCELED", c];
|
| 444 |
-
}''')
|
| 445 |
historyFileSelectDropdown.change(**load_history_from_file_args)
|
| 446 |
downloadFile.change(upload_chat_history, [current_model, downloadFile, user_name], [saveFileName, systemPromptTxt, chatbot])
|
| 447 |
|
|
|
|
| 348 |
inputs=[current_model],
|
| 349 |
outputs=[chatbot, status_display],
|
| 350 |
show_progress=True,
|
| 351 |
+
_js='()=>{clearHistoryHtml();}',
|
| 352 |
)
|
| 353 |
|
| 354 |
retryBtn.click(**start_outputing_args).then(
|
|
|
|
| 434 |
show_progress=True,
|
| 435 |
)
|
| 436 |
historyRefreshBtn.click(**refresh_history_args)
|
| 437 |
+
historyDeleteBtn.click(delete_chat_history, [current_model, historyFileSelectDropdown, user_name], [status_display, historyFileSelectDropdown, chatbot], _js='(a,b,c)=>{return showConfirmationDialog(a, b, c);}')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 438 |
historyFileSelectDropdown.change(**load_history_from_file_args)
|
| 439 |
downloadFile.change(upload_chat_history, [current_model, downloadFile, user_name], [saveFileName, systemPromptTxt, chatbot])
|
| 440 |
|
assets/custom.js
CHANGED
|
@@ -15,7 +15,6 @@ var appTitleDiv = null;
|
|
| 15 |
var chatbot = null;
|
| 16 |
var chatbotWrap = null;
|
| 17 |
var apSwitch = null;
|
| 18 |
-
var empty_botton = null;
|
| 19 |
var messageBotDivs = null;
|
| 20 |
var loginUserForm = null;
|
| 21 |
var logginUser = null;
|
|
@@ -62,7 +61,6 @@ function gradioLoaded(mutations) {
|
|
| 62 |
chatbot = document.querySelector('#chuanhu_chatbot');
|
| 63 |
chatbotWrap = document.querySelector('#chuanhu_chatbot > .wrap');
|
| 64 |
apSwitch = document.querySelector('.apSwitch input[type="checkbox"]');
|
| 65 |
-
empty_botton = document.getElementById("empty_btn")
|
| 66 |
|
| 67 |
if (loginUserForm) {
|
| 68 |
localStorage.setItem("userLogged", true);
|
|
@@ -90,9 +88,6 @@ function gradioLoaded(mutations) {
|
|
| 90 |
}
|
| 91 |
setChatbotScroll();
|
| 92 |
}
|
| 93 |
-
if (empty_botton) {
|
| 94 |
-
emptyHistory();
|
| 95 |
-
}
|
| 96 |
}
|
| 97 |
}
|
| 98 |
}
|
|
@@ -111,6 +106,16 @@ function webLocale() {
|
|
| 111 |
}
|
| 112 |
}
|
| 113 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
function selectHistory() {
|
| 115 |
user_input_ta = user_input_tb.querySelector("textarea");
|
| 116 |
if (user_input_ta) {
|
|
@@ -490,11 +495,6 @@ function clearHistoryHtml() {
|
|
| 490 |
console.log("History Cleared");
|
| 491 |
}
|
| 492 |
}
|
| 493 |
-
function emptyHistory() {
|
| 494 |
-
empty_botton.addEventListener("click", function () {
|
| 495 |
-
clearHistoryHtml();
|
| 496 |
-
});
|
| 497 |
-
}
|
| 498 |
|
| 499 |
// 监视页面内部 DOM 变动
|
| 500 |
var observer = new MutationObserver(function (mutations) {
|
|
|
|
| 15 |
var chatbot = null;
|
| 16 |
var chatbotWrap = null;
|
| 17 |
var apSwitch = null;
|
|
|
|
| 18 |
var messageBotDivs = null;
|
| 19 |
var loginUserForm = null;
|
| 20 |
var logginUser = null;
|
|
|
|
| 61 |
chatbot = document.querySelector('#chuanhu_chatbot');
|
| 62 |
chatbotWrap = document.querySelector('#chuanhu_chatbot > .wrap');
|
| 63 |
apSwitch = document.querySelector('.apSwitch input[type="checkbox"]');
|
|
|
|
| 64 |
|
| 65 |
if (loginUserForm) {
|
| 66 |
localStorage.setItem("userLogged", true);
|
|
|
|
| 88 |
}
|
| 89 |
setChatbotScroll();
|
| 90 |
}
|
|
|
|
|
|
|
|
|
|
| 91 |
}
|
| 92 |
}
|
| 93 |
}
|
|
|
|
| 106 |
}
|
| 107 |
}
|
| 108 |
|
| 109 |
+
function showConfirmationDialog(a, file, c) {
|
| 110 |
+
if (file != "") {
|
| 111 |
+
var result = confirm(deleteConfirm_msg_pref + file + deleteConfirm_msg_suff);
|
| 112 |
+
if (result) {
|
| 113 |
+
return [a, file, c];
|
| 114 |
+
}
|
| 115 |
+
}
|
| 116 |
+
return [a, "CANCELED", c];
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
function selectHistory() {
|
| 120 |
user_input_ta = user_input_tb.querySelector("textarea");
|
| 121 |
if (user_input_ta) {
|
|
|
|
| 495 |
console.log("History Cleared");
|
| 496 |
}
|
| 497 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 498 |
|
| 499 |
// 监视页面内部 DOM 变动
|
| 500 |
var observer = new MutationObserver(function (mutations) {
|