Spaces:
Sleeping
Sleeping
Keldos
commited on
Commit
·
8a9679a
1
Parent(s):
d9d1fb2
WIP: chat-with-more btns actually work
Browse files
ChuanhuChatbot.py
CHANGED
@@ -124,10 +124,6 @@ with gr.Blocks(theme=small_and_beautiful_theme) as demo:
|
|
124 |
)
|
125 |
with gr.Row(elem_id="chatbot-footer"):
|
126 |
with gr.Box(elem_id="chatbot-input-box"):
|
127 |
-
# with gr.Row(elem_id="chatbot-input-btn-bar"):
|
128 |
-
# gr.Button(i18n("📄 上传文档"), variant="secondary", elem_id="upload-doc-btn", elem_classes="chatbot-input-button", scale=0)
|
129 |
-
# gr.Button(i18n("📄 xxx"), variant="secondary", elem_id="upload-index-btn", elem_classes="chatbot-input-button", scale=0)
|
130 |
-
# gr.Button(i18n("📄 xxx"), variant="secondary", elem_id="uplasdfasdfoad-qa-btn", elem_classes="chatbot-input-button", scale=0)
|
131 |
with gr.Row(elem_id="chatbot-input-row"):
|
132 |
gr.HTML(get_html("chatbot_more.html"))
|
133 |
with gr.Row(elem_id="chatbot-input-tb-row"):
|
@@ -279,11 +275,9 @@ with gr.Blocks(theme=small_and_beautiful_theme) as demo:
|
|
279 |
lines=1,
|
280 |
)
|
281 |
with gr.Tab(label=i18n("Extensions")):
|
282 |
-
gr.Markdown("Will be here soon...\n(We hope)")
|
283 |
|
284 |
# changeAPIURLBtn = gr.Button(i18n("🔄 切换API地址"))
|
285 |
-
updateChuanhuBtn = gr.Button(visible=False, elem_classes="invisible-btn", elem_id="update-chuanhu-btn")
|
286 |
-
historySelectBtn = gr.Button(visible=False, elem_classes="invisible-btn", elem_id="history-select-btn")
|
287 |
|
288 |
with gr.Row(elem_id="popup-wrapper"):
|
289 |
with gr.Box(elem_id="chuanhu-popup"):
|
@@ -311,9 +305,9 @@ with gr.Blocks(theme=small_and_beautiful_theme) as demo:
|
|
311 |
# lora_select_dropdown = gr.Dropdown(
|
312 |
# label=i18n("选择LoRA模型"), choices=[], multiselect=False, interactive=True, visible=False
|
313 |
# )
|
314 |
-
with gr.Row():
|
315 |
-
|
316 |
-
|
317 |
language_select_dropdown = gr.Dropdown(
|
318 |
label=i18n("选择回复语言(针对搜索&索引功能)"),
|
319 |
choices=REPLY_LANGUAGES,
|
@@ -391,6 +385,13 @@ with gr.Blocks(theme=small_and_beautiful_theme) as demo:
|
|
391 |
openai_cancel_all_jobs_btn = gr.Button(i18n("取消所有任务"))
|
392 |
add_to_models_btn = gr.Button(i18n("添加训练好的模型到模型列表"), interactive=False)
|
393 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
394 |
# https://github.com/gradio-app/gradio/pull/3296
|
395 |
def create_greeting(request: gr.Request):
|
396 |
if hasattr(request, "username") and request.username: # is not None or is not ""
|
@@ -607,13 +608,27 @@ with gr.Blocks(theme=small_and_beautiful_theme) as demo:
|
|
607 |
[status_display],
|
608 |
show_progress=True,
|
609 |
)
|
610 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
611 |
fn=load_chat_history,
|
612 |
inputs=[current_model, historyFileSelectDropdown, user_name],
|
613 |
outputs=[saveFileName, systemPromptTxt, chatbot],
|
614 |
_js='(a,b,c)=>{return bgSelectHistory(a,b,c);}'
|
615 |
)
|
616 |
|
|
|
|
|
617 |
logging.info(
|
618 |
colorama.Back.GREEN
|
619 |
+ "\n川虎的温馨提示:访问 http://localhost:7860 查看界面"
|
|
|
124 |
)
|
125 |
with gr.Row(elem_id="chatbot-footer"):
|
126 |
with gr.Box(elem_id="chatbot-input-box"):
|
|
|
|
|
|
|
|
|
127 |
with gr.Row(elem_id="chatbot-input-row"):
|
128 |
gr.HTML(get_html("chatbot_more.html"))
|
129 |
with gr.Row(elem_id="chatbot-input-tb-row"):
|
|
|
275 |
lines=1,
|
276 |
)
|
277 |
with gr.Tab(label=i18n("Extensions")):
|
278 |
+
gr.Markdown("Will be here soon...\n(We hope)\nAnd we hope you can help us to make more extensions!")
|
279 |
|
280 |
# changeAPIURLBtn = gr.Button(i18n("🔄 切换API地址"))
|
|
|
|
|
281 |
|
282 |
with gr.Row(elem_id="popup-wrapper"):
|
283 |
with gr.Box(elem_id="chuanhu-popup"):
|
|
|
305 |
# lora_select_dropdown = gr.Dropdown(
|
306 |
# label=i18n("选择LoRA模型"), choices=[], multiselect=False, interactive=True, visible=False
|
307 |
# )
|
308 |
+
# with gr.Row():
|
309 |
+
single_turn_checkbox = gr.Checkbox(label=i18n("单轮对话"), value=False, elem_classes="switch-checkbox", elem_id="gr-single-session-cb")
|
310 |
+
use_websearch_checkbox = gr.Checkbox(label=i18n("使用在线搜索"), value=False, elem_classes="switch-checkbox", elem_id="gr-websearch-cb")
|
311 |
language_select_dropdown = gr.Dropdown(
|
312 |
label=i18n("选择回复语言(针对搜索&索引功能)"),
|
313 |
choices=REPLY_LANGUAGES,
|
|
|
385 |
openai_cancel_all_jobs_btn = gr.Button(i18n("取消所有任务"))
|
386 |
add_to_models_btn = gr.Button(i18n("添加训练好的模型到模型列表"), interactive=False)
|
387 |
|
388 |
+
with gr.Box(elem_id="fake-gradio-components", visible=False):
|
389 |
+
updateChuanhuBtn = gr.Button(visible=False, elem_classes="invisible-btn", elem_id="update-chuanhu-btn")
|
390 |
+
changeSingleSessionBtn = gr.Button(visible=False, elem_classes="invisible-btn", elem_id="change-single-session-btn")
|
391 |
+
changeOnlineSearchBtn = gr.Button(visible=False, elem_classes="invisible-btn", elem_id="change-online-search-btn")
|
392 |
+
historySelectBtn = gr.Button(visible=False, elem_classes="invisible-btn", elem_id="history-select-btn") # Not used
|
393 |
+
|
394 |
+
|
395 |
# https://github.com/gradio-app/gradio/pull/3296
|
396 |
def create_greeting(request: gr.Request):
|
397 |
if hasattr(request, "username") and request.username: # is not None or is not ""
|
|
|
608 |
[status_display],
|
609 |
show_progress=True,
|
610 |
)
|
611 |
+
changeSingleSessionBtn.click(
|
612 |
+
fn=lambda value: gr.Checkbox.update(value=value),
|
613 |
+
inputs=[single_turn_checkbox],
|
614 |
+
outputs=[single_turn_checkbox],
|
615 |
+
_js='(a)=>{return bgChangeSingleSession(a);}'
|
616 |
+
)
|
617 |
+
changeOnlineSearchBtn.click(
|
618 |
+
fn=lambda value: gr.Checkbox.update(value=value),
|
619 |
+
inputs=[use_websearch_checkbox],
|
620 |
+
outputs=[use_websearch_checkbox],
|
621 |
+
_js='(a)=>{return bgChangeOnlineSearch(a);}'
|
622 |
+
)
|
623 |
+
historySelectBtn.click( # This is an experimental feature... Not actually used.
|
624 |
fn=load_chat_history,
|
625 |
inputs=[current_model, historyFileSelectDropdown, user_name],
|
626 |
outputs=[saveFileName, systemPromptTxt, chatbot],
|
627 |
_js='(a,b,c)=>{return bgSelectHistory(a,b,c);}'
|
628 |
)
|
629 |
|
630 |
+
|
631 |
+
|
632 |
logging.info(
|
633 |
colorama.Back.GREEN
|
634 |
+ "\n川虎的温馨提示:访问 http://localhost:7860 查看界面"
|
web_assets/html/chatbot_more.html
CHANGED
@@ -19,7 +19,7 @@
|
|
19 |
<span class="chatbot-input-more-label-group">
|
20 |
<div class="chatbot-input-more-btn last-btn">
|
21 |
<label>
|
22 |
-
<button>
|
23 |
<span class="chatbot-input-more-span">上传文件</span>
|
24 |
<span class="chatbot-input-more-icon">
|
25 |
<svg width="17.6625708px" height="22px" viewBox="0 0 17.6625708 22" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
|
19 |
<span class="chatbot-input-more-label-group">
|
20 |
<div class="chatbot-input-more-btn last-btn">
|
21 |
<label>
|
22 |
+
<button id="upload-files-btn">
|
23 |
<span class="chatbot-input-more-span">上传文件</span>
|
24 |
<span class="chatbot-input-more-icon">
|
25 |
<svg width="17.6625708px" height="22px" viewBox="0 0 17.6625708 22" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
web_assets/javascript/ChuanhuChat.js
CHANGED
@@ -100,6 +100,9 @@ function initialize() {
|
|
100 |
setPopupBoxPosition();
|
101 |
setSlider();
|
102 |
checkModel();
|
|
|
|
|
|
|
103 |
// setScrollShadow();
|
104 |
|
105 |
if (!historyLoaded) loadHistoryHtml();
|
|
|
100 |
setPopupBoxPosition();
|
101 |
setSlider();
|
102 |
checkModel();
|
103 |
+
transUpload();
|
104 |
+
// transCheckbox();
|
105 |
+
setCheckboxes();
|
106 |
// setScrollShadow();
|
107 |
|
108 |
if (!historyLoaded) loadHistoryHtml();
|
web_assets/javascript/fake-gradio.js
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
// Fake gradio components!
|
3 |
+
|
4 |
+
// buttons
|
5 |
+
function newChatClick() {
|
6 |
+
gradioApp().querySelector('#empty-btn').click();
|
7 |
+
}
|
8 |
+
|
9 |
+
// index files
|
10 |
+
function transUpload() {
|
11 |
+
var grUploader = gradioApp().querySelector("#upload-index-file > .center.flex");
|
12 |
+
var chatbotUploader = gradioApp().querySelector("#upload-files-btn");
|
13 |
+
let uploaderEvents = ["click", "drag", "dragend", "dragenter", "dragleave", "dragover", "dragstart", "drop"];
|
14 |
+
transEventListeners(chatbotUploader, grUploader, uploaderEvents);
|
15 |
+
}
|
16 |
+
|
17 |
+
// checkbox
|
18 |
+
var grSingleSessionCB;
|
19 |
+
var grOnlineSearchCB;
|
20 |
+
var chatbotSingleSessionCB;
|
21 |
+
var chatbotOnlineSearchCB;
|
22 |
+
function setCheckboxes() {
|
23 |
+
chatbotSingleSessionCB = gradioApp().querySelector('input[name="single-session-cb"]');
|
24 |
+
chatbotOnlineSearchCB = gradioApp().querySelector('input[name="online-search-cb"]');
|
25 |
+
grSingleSessionCB = gradioApp().querySelector("#gr-single-session-cb > label > input");
|
26 |
+
grOnlineSearchCB = gradioApp().querySelector("#gr-websearch-cb > label> input");
|
27 |
+
|
28 |
+
chatbotSingleSessionCB.addEventListener('change', (e) => {
|
29 |
+
grSingleSessionCB.checked = chatbotSingleSessionCB.checked;
|
30 |
+
gradioApp().querySelector('#change-single-session-btn').click();
|
31 |
+
});
|
32 |
+
chatbotOnlineSearchCB.addEventListener('change', (e) => {
|
33 |
+
grOnlineSearchCB.checked = chatbotOnlineSearchCB.checked;
|
34 |
+
gradioApp().querySelector('#change-online-search-btn').click();
|
35 |
+
});
|
36 |
+
grSingleSessionCB.addEventListener('change', (e) => {
|
37 |
+
chatbotSingleSessionCB.checked = grSingleSessionCB.checked;
|
38 |
+
});
|
39 |
+
grOnlineSearchCB.addEventListener('change', (e) => {
|
40 |
+
chatbotOnlineSearchCB.checked = grOnlineSearchCB.checked;
|
41 |
+
});
|
42 |
+
}
|
43 |
+
|
44 |
+
function bgChangeSingleSession() {
|
45 |
+
// const grSingleSessionCB = gradioApp().querySelector("#gr-single-session-cb > label > input");
|
46 |
+
let a = chatbotSingleSessionCB.checked;
|
47 |
+
return [a];
|
48 |
+
}
|
49 |
+
function bgChangeOnlineSearch() {
|
50 |
+
// const grOnlineSearchCB = gradioApp().querySelector("#gr-websearch-cb > label> input");
|
51 |
+
let a = chatbotOnlineSearchCB.checked;
|
52 |
+
return [a];
|
53 |
+
}
|
54 |
+
|
55 |
+
// UTILS
|
56 |
+
function transEventListeners(target, source, events) {
|
57 |
+
events.forEach((sourceEvent) => {
|
58 |
+
target.addEventListener(sourceEvent, function (targetEvent) {
|
59 |
+
if(targetEvent.preventDefault) targetEvent.preventDefault();
|
60 |
+
if(targetEvent.stopPropagation) targetEvent.stopPropagation();
|
61 |
+
|
62 |
+
source.dispatchEvent(new Event(sourceEvent, {detail: targetEvent.detail}));
|
63 |
+
// console.log(targetEvent.detail);
|
64 |
+
});
|
65 |
+
});
|
66 |
+
/* 事实上,我发现这样写的大多数gradio组件并不适用。。所以。。。生气 */
|
67 |
+
}
|
68 |
+
|
69 |
+
function bgSelectHistory(a,b,c){
|
70 |
+
const historySelectorInput = gradioApp().querySelector('#history-select-dropdown input');
|
71 |
+
let file = historySelectorInput.value;
|
72 |
+
return [a,file,c]
|
73 |
+
}
|
web_assets/javascript/utils.js
CHANGED
@@ -1,25 +1,4 @@
|
|
1 |
|
2 |
-
var gradioUploader = null;
|
3 |
-
|
4 |
-
function testUpload(target) {
|
5 |
-
gradioUploader = gradioApp().querySelector("#upload-index-file > .center.flex");
|
6 |
-
let uploaderEvents = ["click", "drag", "dragend", "dragenter", "dragleave", "dragover", "dragstart", "drop"];
|
7 |
-
transEventListeners(target, gradioUploader, uploaderEvents);
|
8 |
-
}
|
9 |
-
|
10 |
-
|
11 |
-
function transEventListeners(target, source, events) {
|
12 |
-
events.forEach((sourceEvent) => {
|
13 |
-
target.addEventListener(sourceEvent, function (targetEvent) {
|
14 |
-
if(targetEvent.preventDefault) targetEvent.preventDefault();
|
15 |
-
if(targetEvent.stopPropagation) targetEvent.stopPropagation();
|
16 |
-
|
17 |
-
source.dispatchEvent(new Event(sourceEvent, {detail: targetEvent.detail}));
|
18 |
-
console.log(targetEvent.detail);
|
19 |
-
});
|
20 |
-
});
|
21 |
-
}
|
22 |
-
|
23 |
|
24 |
function isImgUrl(url) {
|
25 |
const imageExtensions = /\.(jpg|jpeg|png|gif|bmp|webp)$/i;
|
|
|
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
function isImgUrl(url) {
|
4 |
const imageExtensions = /\.(jpg|jpeg|png|gif|bmp|webp)$/i;
|
web_assets/javascript/webui.js
CHANGED
@@ -1,8 +1,4 @@
|
|
1 |
|
2 |
-
function newChatClick() {
|
3 |
-
gradioApp().querySelector('#empty-btn').click();
|
4 |
-
}
|
5 |
-
|
6 |
function openSettingBox() {
|
7 |
chuanhuPopup.classList.add('showBox');
|
8 |
popupWrapper.classList.add('showBox');
|
@@ -277,11 +273,6 @@ function setHistroyPanel() {
|
|
277 |
// });
|
278 |
// }
|
279 |
|
280 |
-
// function bgSelectHistory(a,b,c){
|
281 |
-
// const historySelectorInput = gradioApp().querySelector('#history-select-dropdown input');
|
282 |
-
// let file = historySelectorInput.value;
|
283 |
-
// return [a,file,c]
|
284 |
-
// }
|
285 |
|
286 |
// function testTrain() {
|
287 |
|
|
|
1 |
|
|
|
|
|
|
|
|
|
2 |
function openSettingBox() {
|
3 |
chuanhuPopup.classList.add('showBox');
|
4 |
popupWrapper.classList.add('showBox');
|
|
|
273 |
// });
|
274 |
// }
|
275 |
|
|
|
|
|
|
|
|
|
|
|
276 |
|
277 |
// function testTrain() {
|
278 |
|