Spaces:
Sleeping
Sleeping
Keldos
commited on
Commit
•
58a0a81
1
Parent(s):
d65cba4
refactor: 微调python中js写法,加入部分测试js (WIP)
Browse files- ChuanhuChatbot.py +3 -3
- web_assets/javascript/utils.js +67 -0
ChuanhuChatbot.py
CHANGED
@@ -107,7 +107,7 @@ with gr.Blocks(theme=small_and_beautiful_theme) as demo:
|
|
107 |
multiselect=False,
|
108 |
value=REPLY_LANGUAGES[0],
|
109 |
)
|
110 |
-
index_files = gr.Files(label=i18n("上传"), type="file")
|
111 |
two_column = gr.Checkbox(label=i18n("双栏pdf"), value=advance_docs["pdf"].get("two_column", False))
|
112 |
summarize_btn = gr.Button(i18n("总结"))
|
113 |
# TODO: 公式ocr
|
@@ -376,7 +376,7 @@ with gr.Blocks(theme=small_and_beautiful_theme) as demo:
|
|
376 |
inputs=[current_model],
|
377 |
outputs=[chatbot, status_display],
|
378 |
show_progress=True,
|
379 |
-
_js='
|
380 |
)
|
381 |
|
382 |
retryBtn.click(**start_outputing_args).then(
|
@@ -493,7 +493,7 @@ with gr.Blocks(theme=small_and_beautiful_theme) as demo:
|
|
493 |
# [status_display],
|
494 |
# show_progress=True,
|
495 |
# )
|
496 |
-
checkUpdateBtn.click(fn=None, _js='
|
497 |
|
498 |
# Invisible elements
|
499 |
updateChuanhuBtn.click(
|
|
|
107 |
multiselect=False,
|
108 |
value=REPLY_LANGUAGES[0],
|
109 |
)
|
110 |
+
index_files = gr.Files(label=i18n("上传"), type="file", elem_id="upload-index-file")
|
111 |
two_column = gr.Checkbox(label=i18n("双栏pdf"), value=advance_docs["pdf"].get("two_column", False))
|
112 |
summarize_btn = gr.Button(i18n("总结"))
|
113 |
# TODO: 公式ocr
|
|
|
376 |
inputs=[current_model],
|
377 |
outputs=[chatbot, status_display],
|
378 |
show_progress=True,
|
379 |
+
_js='clearHistoryHtml',
|
380 |
)
|
381 |
|
382 |
retryBtn.click(**start_outputing_args).then(
|
|
|
493 |
# [status_display],
|
494 |
# show_progress=True,
|
495 |
# )
|
496 |
+
checkUpdateBtn.click(fn=None, _js='manualCheckUpdate')
|
497 |
|
498 |
# Invisible elements
|
499 |
updateChuanhuBtn.click(
|
web_assets/javascript/utils.js
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
/* NOTE: These reload functions are not used in the current version of the code.
|
25 |
+
* From stable-diffusion-webui
|
26 |
+
*/
|
27 |
+
function restart_reload() {
|
28 |
+
document.body.innerHTML = '<h1 style="font-family:ui-monospace,monospace;margin-top:20%;color:lightgray;text-align:center;">Reloading...</h1>';
|
29 |
+
|
30 |
+
var requestPing = function () {
|
31 |
+
requestGet("./internal/ping", {}, function (data) {
|
32 |
+
location.reload();
|
33 |
+
}, function () {
|
34 |
+
setTimeout(requestPing, 500);
|
35 |
+
});
|
36 |
+
};
|
37 |
+
|
38 |
+
setTimeout(requestPing, 2000);
|
39 |
+
|
40 |
+
return [];
|
41 |
+
}
|
42 |
+
|
43 |
+
function requestGet(url, data, handler, errorHandler) {
|
44 |
+
var xhr = new XMLHttpRequest();
|
45 |
+
var args = Object.keys(data).map(function (k) {
|
46 |
+
return encodeURIComponent(k) + '=' + encodeURIComponent(data[k]);
|
47 |
+
}).join('&');
|
48 |
+
xhr.open("GET", url + "?" + args, true);
|
49 |
+
|
50 |
+
xhr.onreadystatechange = function () {
|
51 |
+
if (xhr.readyState === 4) {
|
52 |
+
if (xhr.status === 200) {
|
53 |
+
try {
|
54 |
+
var js = JSON.parse(xhr.responseText);
|
55 |
+
handler(js);
|
56 |
+
} catch (error) {
|
57 |
+
console.error(error);
|
58 |
+
errorHandler();
|
59 |
+
}
|
60 |
+
} else {
|
61 |
+
errorHandler();
|
62 |
+
}
|
63 |
+
}
|
64 |
+
};
|
65 |
+
var js = JSON.stringify(data);
|
66 |
+
xhr.send(js);
|
67 |
+
}
|