|
|
|
|
|
|
|
|
|
function newChatClick() { |
|
gradioApp().querySelector('#empty-btn').click(); |
|
} |
|
function jsonDownloadClick() { |
|
gradioApp().querySelector('#gr-history-download-btn').click(); |
|
} |
|
function mdDownloadClick() { |
|
gradioApp().querySelector('#gr-markdown-export-btn').click(); |
|
gradioApp().querySelector('#gr-history-mardown-download-btn').click(); |
|
|
|
|
|
} |
|
|
|
|
|
function setUploader() { |
|
transUpload(); |
|
var uploaderObserver = new MutationObserver(function (mutations) { |
|
var fileInput = null; |
|
var fileCount = 0; |
|
fileInput = gradioApp().querySelector("#upload-index-file table.file-preview"); |
|
var fileCountSpan = gradioApp().querySelector("#uploaded-files-count"); |
|
if (fileInput) { |
|
chatbotArea.classList.add('with-file'); |
|
fileCount = fileInput.querySelectorAll('tbody > tr.file').length; |
|
fileCountSpan.innerText = fileCount; |
|
} else { |
|
chatbotArea.classList.remove('with-file'); |
|
statusDisplayMessage(""); |
|
fileCount = 0; |
|
transUpload(); |
|
} |
|
}); |
|
uploaderObserver.observe(uploaderIndicator, {attributes: true}) |
|
uploaderObserver.observe(uploaderIndicator2, {attributes: true}) |
|
} |
|
var grUploader; |
|
var chatbotUploader; |
|
var handleClick = function() { |
|
grUploader.click(); |
|
|
|
}; |
|
function transUpload() { |
|
chatbotUploader = gradioApp().querySelector("#upload-files-btn"); |
|
chatbotUploader.removeEventListener('click', handleClick); |
|
grUploader = gradioApp().querySelector("#upload-index-file > .center.flex"); |
|
|
|
|
|
|
|
|
|
chatbotUploader.addEventListener('click', handleClick); |
|
} |
|
|
|
|
|
var grSingleSessionCB; |
|
var grOnlineSearchCB; |
|
var chatbotSingleSessionCB; |
|
var chatbotOnlineSearchCB; |
|
function setCheckboxes() { |
|
chatbotSingleSessionCB = gradioApp().querySelector('input[name="single-session-cb"]'); |
|
chatbotOnlineSearchCB = gradioApp().querySelector('input[name="online-search-cb"]'); |
|
grSingleSessionCB = gradioApp().querySelector("#gr-single-session-cb > label > input"); |
|
grOnlineSearchCB = gradioApp().querySelector("#gr-websearch-cb > label> input"); |
|
|
|
chatbotSingleSessionCB.addEventListener('change', (e) => { |
|
grSingleSessionCB.checked = chatbotSingleSessionCB.checked; |
|
gradioApp().querySelector('#change-single-session-btn').click(); |
|
}); |
|
chatbotOnlineSearchCB.addEventListener('change', (e) => { |
|
grOnlineSearchCB.checked = chatbotOnlineSearchCB.checked; |
|
gradioApp().querySelector('#change-online-search-btn').click(); |
|
}); |
|
grSingleSessionCB.addEventListener('change', (e) => { |
|
chatbotSingleSessionCB.checked = grSingleSessionCB.checked; |
|
}); |
|
grOnlineSearchCB.addEventListener('change', (e) => { |
|
chatbotOnlineSearchCB.checked = grOnlineSearchCB.checked; |
|
}); |
|
} |
|
|
|
function bgChangeSingleSession() { |
|
|
|
let a = chatbotSingleSessionCB.checked; |
|
return [a]; |
|
} |
|
function bgChangeOnlineSearch() { |
|
|
|
let a = chatbotOnlineSearchCB.checked; |
|
return [a]; |
|
} |
|
|
|
function updateCheckboxes() { |
|
chatbotSingleSessionCB.checked = grSingleSessionCB.checked; |
|
chatbotOnlineSearchCB.checked = grOnlineSearchCB.checked; |
|
} |
|
|
|
|
|
function transEventListeners(target, source, events) { |
|
events.forEach((sourceEvent) => { |
|
target.addEventListener(sourceEvent, function (targetEvent) { |
|
if(targetEvent.preventDefault) targetEvent.preventDefault(); |
|
if(targetEvent.stopPropagation) targetEvent.stopPropagation(); |
|
|
|
source.dispatchEvent(new Event(sourceEvent, {detail: targetEvent.detail})); |
|
|
|
}); |
|
}); |
|
|
|
} |
|
|
|
function bgSelectHistory(a,b){ |
|
const historySelectorInput = gradioApp().querySelector('#history-select-dropdown input'); |
|
let file = historySelectorInput.value; |
|
return [a,file] |
|
} |
|
|
|
function bgRebootChuanhu() { |
|
rebootChuanhuBtn.click() |
|
} |