Spaces:
Sleeping
Sleeping
Keldos
commited on
Commit
•
e741d7d
1
Parent(s):
544e08e
WIP: 为重命名和删除对话按钮绑定后台处理事件
Browse files- ChuanhuChatbot.py +3 -1
- locale/en_US.json +1 -0
- locale/ja_JP.json +1 -0
- locale/ko_KR.json +1 -0
- locale/ru_RU.json +1 -0
- locale/sv_SE.json +1 -0
- web_assets/html/web_config.html +1 -0
- web_assets/javascript/ChuanhuChat.js +7 -0
- web_assets/javascript/chat-list.js +24 -2
- web_assets/javascript/localization.js +1 -0
- web_assets/stylesheet/override-gradio.css +3 -0
ChuanhuChatbot.py
CHANGED
@@ -87,7 +87,7 @@ with gr.Blocks(theme=small_and_beautiful_theme) as demo:
|
|
87 |
# container=False,
|
88 |
)
|
89 |
with gr.Column(scale=1):
|
90 |
-
saveHistoryBtn = gr.Button(i18n("💾 保存对话"))
|
91 |
exportMarkdownBtn = gr.Button(i18n("📝 导出为Markdown"))
|
92 |
gr.Markdown(i18n("默认保存于history文件夹"))
|
93 |
with gr.Row():
|
@@ -411,6 +411,7 @@ with gr.Blocks(theme=small_and_beautiful_theme) as demo:
|
|
411 |
updateFailure_i18n=i18n('更新失败,请尝试<a href="https://github.com/GaiZhenbiao/ChuanhuChatGPT/wiki/使用教程#手动更新" target="_blank">手动更新</a>'),
|
412 |
regenerate_i18n=i18n("重新生成"),
|
413 |
deleteRound_i18n=i18n("删除这轮问答"),
|
|
|
414 |
))
|
415 |
with gr.Box(elem_id="fake-gradio-components", visible=False):
|
416 |
updateChuanhuBtn = gr.Button(visible=False, elem_classes="invisible-btn", elem_id="update-chuanhu-btn")
|
@@ -574,6 +575,7 @@ with gr.Blocks(theme=small_and_beautiful_theme) as demo:
|
|
574 |
[current_model, saveFileName, chatbot, user_name],
|
575 |
downloadFile,
|
576 |
show_progress=True,
|
|
|
577 |
)
|
578 |
saveHistoryBtn.click(get_history_list, [user_name], [historyFileSelectDropdown])
|
579 |
exportMarkdownBtn.click(
|
|
|
87 |
# container=False,
|
88 |
)
|
89 |
with gr.Column(scale=1):
|
90 |
+
saveHistoryBtn = gr.Button(i18n("💾 保存对话"), elem_id="gr-history-save-btn")
|
91 |
exportMarkdownBtn = gr.Button(i18n("📝 导出为Markdown"))
|
92 |
gr.Markdown(i18n("默认保存于history文件夹"))
|
93 |
with gr.Row():
|
|
|
411 |
updateFailure_i18n=i18n('更新失败,请尝试<a href="https://github.com/GaiZhenbiao/ChuanhuChatGPT/wiki/使用教程#手动更新" target="_blank">手动更新</a>'),
|
412 |
regenerate_i18n=i18n("重新生成"),
|
413 |
deleteRound_i18n=i18n("删除这轮问答"),
|
414 |
+
renameChat_i18n=i18n("重命名该对话"),
|
415 |
))
|
416 |
with gr.Box(elem_id="fake-gradio-components", visible=False):
|
417 |
updateChuanhuBtn = gr.Button(visible=False, elem_classes="invisible-btn", elem_id="update-chuanhu-btn")
|
|
|
575 |
[current_model, saveFileName, chatbot, user_name],
|
576 |
downloadFile,
|
577 |
show_progress=True,
|
578 |
+
_js='(a,b,c,d)=>{return saveChatHistory(a,b,c,d);}'
|
579 |
)
|
580 |
saveHistoryBtn.click(get_history_list, [user_name], [historyFileSelectDropdown])
|
581 |
exportMarkdownBtn.click(
|
locale/en_US.json
CHANGED
@@ -54,6 +54,7 @@
|
|
54 |
"仅供查看": "For viewing only",
|
55 |
"你真的要删除 ": "Are you sure you want to delete ",
|
56 |
" 吗?": " ?",
|
|
|
57 |
"🔄 检查更新...": "🔄 Check for Update...",
|
58 |
"您使用的就是最新版!": "You are using the latest version!",
|
59 |
"正在尝试更新...": "Trying to update...",
|
|
|
54 |
"仅供查看": "For viewing only",
|
55 |
"你真的要删除 ": "Are you sure you want to delete ",
|
56 |
" 吗?": " ?",
|
57 |
+
"重命名该对话": "Rename this chat",
|
58 |
"🔄 检查更新...": "🔄 Check for Update...",
|
59 |
"您使用的就是最新版!": "You are using the latest version!",
|
60 |
"正在尝试更新...": "Trying to update...",
|
locale/ja_JP.json
CHANGED
@@ -54,6 +54,7 @@
|
|
54 |
"仅供查看": "閲覧専用",
|
55 |
"你真的要删除 ": "本当に ",
|
56 |
" 吗?": " を削除してもよろしいですか?",
|
|
|
57 |
"🔄 检查更新...": "🔄 アップデートをチェック...",
|
58 |
"您使用的就是最新版!": "最新バージョンを使用しています!",
|
59 |
"正在尝试更新...": "更新を試みています...",
|
|
|
54 |
"仅供查看": "閲覧専用",
|
55 |
"你真的要删除 ": "本当に ",
|
56 |
" 吗?": " を削除してもよろしいですか?",
|
57 |
+
"重命名该对话": "会話の名前を変更",
|
58 |
"🔄 检查更新...": "🔄 アップデートをチェック...",
|
59 |
"您使用的就是最新版!": "最新バージョンを使用しています!",
|
60 |
"正在尝试更新...": "更新を試みています...",
|
locale/ko_KR.json
CHANGED
@@ -54,6 +54,7 @@
|
|
54 |
"仅供查看": "읽기 전용",
|
55 |
"你真的要删除 ": "정말로 ",
|
56 |
" 吗?": " 을(를) 삭제하시겠습니까?",
|
|
|
57 |
"🔄 检查更新...": "🔄 업데이트 확인...",
|
58 |
"您使用的就是最新版!": "최신 버전을 사용하고 있습니다!",
|
59 |
"正在尝试更新...": "업데이트를 시도 중...",
|
|
|
54 |
"仅供查看": "읽기 전용",
|
55 |
"你真的要删除 ": "정말로 ",
|
56 |
" 吗?": " 을(를) 삭제하시겠습니까?",
|
57 |
+
"重命名该对话": "대화 이름 변경",
|
58 |
"🔄 检查更新...": "🔄 업데이트 확인...",
|
59 |
"您使用的就是最新版!": "최신 버전을 사용하고 있습니다!",
|
60 |
"正在尝试更新...": "업데이트를 시도 중...",
|
locale/ru_RU.json
CHANGED
@@ -54,6 +54,7 @@
|
|
54 |
"仅供查看": "Только для просмотра",
|
55 |
"你真的要删除 ": "Вы уверены, что хотите удалить ",
|
56 |
" 吗?": " ?",
|
|
|
57 |
"🔄 检查更新...": "🔄 Проверить обновления...",
|
58 |
"您使用的就是最新版!": "Вы используете последнюю версию!",
|
59 |
"正在尝试更新...": "Попытка обновления...",
|
|
|
54 |
"仅供查看": "Только для просмотра",
|
55 |
"你真的要删除 ": "Вы уверены, что хотите удалить ",
|
56 |
" 吗?": " ?",
|
57 |
+
"重命名该对话": "Переименовать этот диалог",
|
58 |
"🔄 检查更新...": "🔄 Проверить обновления...",
|
59 |
"您使用的就是最新版!": "Вы используете последнюю версию!",
|
60 |
"正在尝试更新...": "Попытка обновления...",
|
locale/sv_SE.json
CHANGED
@@ -54,6 +54,7 @@
|
|
54 |
"仅供查看": "Endast för visning",
|
55 |
"你真的要删除 ": "Är du säker på att du vill ta bort ",
|
56 |
" 吗?": " ?",
|
|
|
57 |
"🔄 检查更新...": "🔄 Sök efter uppdateringar...",
|
58 |
"您使用的就是最新版!": "Du använder den senaste versionen!",
|
59 |
"正在尝试更新...": "Försöker uppdatera...",
|
|
|
54 |
"仅供查看": "Endast för visning",
|
55 |
"你真的要删除 ": "Är du säker på att du vill ta bort ",
|
56 |
" 吗?": " ?",
|
57 |
+
"重命名该对话": "Byt namn på dialogen",
|
58 |
"🔄 检查更新...": "🔄 Sök efter uppdateringar...",
|
59 |
"您使用的就是最新版!": "Du använder den senaste versionen!",
|
60 |
"正在尝试更新...": "Försöker uppdatera...",
|
web_assets/html/web_config.html
CHANGED
@@ -10,5 +10,6 @@
|
|
10 |
<span id="updateFailure_i18n">{updateFailure_i18n}</span>
|
11 |
<span id="regenerate_i18n">{regenerate_i18n}</span>
|
12 |
<span id="deleteRound_i18n">{deleteRound_i18n}</span>
|
|
|
13 |
</div>
|
14 |
</div>
|
|
|
10 |
<span id="updateFailure_i18n">{updateFailure_i18n}</span>
|
11 |
<span id="regenerate_i18n">{regenerate_i18n}</span>
|
12 |
<span id="deleteRound_i18n">{deleteRound_i18n}</span>
|
13 |
+
<span id="renameChat_i18n">{renameChat_i18n}</span>
|
14 |
</div>
|
15 |
</div>
|
web_assets/javascript/ChuanhuChat.js
CHANGED
@@ -15,6 +15,7 @@ var chatbotArea = null;
|
|
15 |
var chatbot = null;
|
16 |
var chatbotIndicator = null;
|
17 |
var uploaderIndicator = null;
|
|
|
18 |
var chatbotWrap = null;
|
19 |
var apSwitch = null;
|
20 |
var messageBotDivs = null;
|
@@ -47,6 +48,7 @@ function addInit() {
|
|
47 |
|
48 |
chatbotIndicator = gradioApp().querySelector('#chuanhu-chatbot > div.wrap');
|
49 |
uploaderIndicator = gradioApp().querySelector('#upload-index-file > div.wrap');
|
|
|
50 |
|
51 |
for (let elem in needInit) {
|
52 |
if (needInit[elem] == null) {
|
@@ -56,6 +58,7 @@ function addInit() {
|
|
56 |
}
|
57 |
|
58 |
chatbotObserver.observe(chatbotIndicator, { attributes: true });
|
|
|
59 |
setUploader();
|
60 |
|
61 |
return true;
|
@@ -365,6 +368,10 @@ var chatbotObserver = new MutationObserver(() => {
|
|
365 |
}
|
366 |
});
|
367 |
|
|
|
|
|
|
|
|
|
368 |
// 监视页面内部 DOM 变动
|
369 |
var gradioObserver = new MutationObserver(function (mutations) {
|
370 |
for (var i = 0; i < mutations.length; i++) {
|
|
|
15 |
var chatbot = null;
|
16 |
var chatbotIndicator = null;
|
17 |
var uploaderIndicator = null;
|
18 |
+
var chatListIndicator = null;
|
19 |
var chatbotWrap = null;
|
20 |
var apSwitch = null;
|
21 |
var messageBotDivs = null;
|
|
|
48 |
|
49 |
chatbotIndicator = gradioApp().querySelector('#chuanhu-chatbot > div.wrap');
|
50 |
uploaderIndicator = gradioApp().querySelector('#upload-index-file > div.wrap');
|
51 |
+
chatListIndicator = gradioApp().querySelector('#history-select-dropdown > div.wrap');
|
52 |
|
53 |
for (let elem in needInit) {
|
54 |
if (needInit[elem] == null) {
|
|
|
58 |
}
|
59 |
|
60 |
chatbotObserver.observe(chatbotIndicator, { attributes: true });
|
61 |
+
chatListObserver.observe(chatListIndicator, { attributes: true });
|
62 |
setUploader();
|
63 |
|
64 |
return true;
|
|
|
368 |
}
|
369 |
});
|
370 |
|
371 |
+
var chatListObserver = new MutationObserver(() => {
|
372 |
+
setChatList();
|
373 |
+
});
|
374 |
+
|
375 |
// 监视页面内部 DOM 变动
|
376 |
var gradioObserver = new MutationObserver(function (mutations) {
|
377 |
for (var i = 0; i < mutations.length; i++) {
|
web_assets/javascript/chat-list.js
CHANGED
@@ -4,6 +4,8 @@ function setChatList() {
|
|
4 |
var chatList = gradioApp().querySelector('fieldset#history-select-dropdown');
|
5 |
selectedChat = chatList.querySelector(".wrap label.selected")
|
6 |
if (!selectedChat || selectedChat.classList.contains('added-chat-btns')) {
|
|
|
|
|
7 |
return;
|
8 |
}
|
9 |
|
@@ -14,12 +16,32 @@ function setChatList() {
|
|
14 |
ChatSelectedBtns.classList.add('chat-selected-btns');
|
15 |
selectedChat.classList.add('added-chat-btns');
|
16 |
ChatSelectedBtns.innerHTML = selectedChatBtns;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
selectedChat.appendChild(ChatSelectedBtns);
|
18 |
|
19 |
return;
|
20 |
}
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
const selectedChatBtns = `
|
23 |
-
<button><svg class="icon-need-hover" stroke="currentColor" fill="none" stroke-width="2" height="18px" width="18px" viewBox="0 0 24 24" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><path d="M12 20h9"></path><path d="M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z"></path></svg></button>
|
24 |
-
<button><svg class="icon-need-hover" stroke="currentColor" fill="none" stroke-width="2" height="18px" width="18px" viewBox="0 0 24 24" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><polyline points="3 6 5 6 21 6"></polyline><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path><line x1="10" y1="11" x2="10" y2="17"></line><line x1="14" y1="11" x2="14" y2="17"></line></svg></button>
|
25 |
`
|
|
|
4 |
var chatList = gradioApp().querySelector('fieldset#history-select-dropdown');
|
5 |
selectedChat = chatList.querySelector(".wrap label.selected")
|
6 |
if (!selectedChat || selectedChat.classList.contains('added-chat-btns')) {
|
7 |
+
chatList.querySelector('.chat-selected-btns')?.remove(); // remove old buttons
|
8 |
+
chatList.querySelectorAll('.added-chat-btns').forEach(chat => chat.classList.remove('added-chat-btns'));
|
9 |
return;
|
10 |
}
|
11 |
|
|
|
16 |
ChatSelectedBtns.classList.add('chat-selected-btns');
|
17 |
selectedChat.classList.add('added-chat-btns');
|
18 |
ChatSelectedBtns.innerHTML = selectedChatBtns;
|
19 |
+
|
20 |
+
var renameBtn = ChatSelectedBtns.querySelector('#history-rename-btn');
|
21 |
+
renameBtn.addEventListener('click', function () {
|
22 |
+
gradioApp().querySelector('#gr-history-save-btn').click();
|
23 |
+
});
|
24 |
+
|
25 |
+
var deleteBtn = ChatSelectedBtns.querySelector('#history-delete-btn');
|
26 |
+
deleteBtn.addEventListener('click', function () {
|
27 |
+
gradioApp().querySelector('#gr-history-delete-btn').click();
|
28 |
+
});
|
29 |
selectedChat.appendChild(ChatSelectedBtns);
|
30 |
|
31 |
return;
|
32 |
}
|
33 |
|
34 |
+
function saveChatHistory(a, b, c, d) {
|
35 |
+
var fileName = b;
|
36 |
+
fileName = prompt(renameChat_i18n, b);
|
37 |
+
if (fileName && fileName.trim() !== "") {
|
38 |
+
return [a, fileName, c, d];
|
39 |
+
} else {
|
40 |
+
return [a, "", c, d];
|
41 |
+
}
|
42 |
+
}
|
43 |
+
|
44 |
const selectedChatBtns = `
|
45 |
+
<button id="history-rename-btn"><svg class="icon-need-hover" stroke="currentColor" fill="none" stroke-width="2" height="18px" width="18px" viewBox="0 0 24 24" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><path d="M12 20h9"></path><path d="M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z"></path></svg></button>
|
46 |
+
<button id="history-delete-btn"><svg class="icon-need-hover" stroke="currentColor" fill="none" stroke-width="2" height="18px" width="18px" viewBox="0 0 24 24" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><polyline points="3 6 5 6 21 6"></polyline><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path><line x1="10" y1="11" x2="10" y2="17"></line><line x1="14" y1="11" x2="14" y2="17"></line></svg></button>
|
47 |
`
|
web_assets/javascript/localization.js
CHANGED
@@ -23,6 +23,7 @@ function setLoclize() {
|
|
23 |
updateFailure_i18n = gradioApp().querySelector('#updateFailure_i18n').innerText;
|
24 |
regenerate_i18n = gradioApp().querySelector('#regenerate_i18n').innerText;
|
25 |
deleteRound_i18n = gradioApp().querySelector('#deleteRound_i18n').innerText;
|
|
|
26 |
}
|
27 |
|
28 |
function i18n(msg) {
|
|
|
23 |
updateFailure_i18n = gradioApp().querySelector('#updateFailure_i18n').innerText;
|
24 |
regenerate_i18n = gradioApp().querySelector('#regenerate_i18n').innerText;
|
25 |
deleteRound_i18n = gradioApp().querySelector('#deleteRound_i18n').innerText;
|
26 |
+
renameChat_i18n = gradioApp().querySelector('#renameChat_i18n').innerText;
|
27 |
}
|
28 |
|
29 |
function i18n(msg) {
|
web_assets/stylesheet/override-gradio.css
CHANGED
@@ -46,6 +46,9 @@ fieldset#history-select-dropdown .wrap label.selected {
|
|
46 |
background: var(--message-list-background-selected);
|
47 |
padding: 10px 64px 10px 16px;
|
48 |
}
|
|
|
|
|
|
|
49 |
fieldset#history-select-dropdown .wrap label > span {
|
50 |
/* font-size: small; */
|
51 |
margin-left: 0;
|
|
|
46 |
background: var(--message-list-background-selected);
|
47 |
padding: 10px 64px 10px 16px;
|
48 |
}
|
49 |
+
fieldset#history-select-dropdown .wrap label:not(.selected) .chat-selected-btns{
|
50 |
+
display: none;
|
51 |
+
}
|
52 |
fieldset#history-select-dropdown .wrap label > span {
|
53 |
/* font-size: small; */
|
54 |
margin-left: 0;
|