再修改亿些细节
This commit is contained in:
@ -79,6 +79,7 @@ class ChatBot(ChatBotFrame):
|
|||||||
with gr.Box(elem_id='chat_box'):
|
with gr.Box(elem_id='chat_box'):
|
||||||
with gr.Row():
|
with gr.Row():
|
||||||
gr.Button(elem_classes='sm_btn').style(size='sm', full_width=False)
|
gr.Button(elem_classes='sm_btn').style(size='sm', full_width=False)
|
||||||
|
gr.HTML(func_box.get_html("appearance_switcher.html").format(label=""), elem_classes="insert_block")
|
||||||
with gr.Row():
|
with gr.Row():
|
||||||
self.txt = gr.Textbox(show_label=False, placeholder="Input question here.", elem_classes='chat_input').style(container=False)
|
self.txt = gr.Textbox(show_label=False, placeholder="Input question here.", elem_classes='chat_input').style(container=False)
|
||||||
self.input_copy = gr.State('')
|
self.input_copy = gr.State('')
|
||||||
|
|||||||
@ -72,6 +72,14 @@ mspace {
|
|||||||
.sm_btn {
|
.sm_btn {
|
||||||
position: relative;
|
position: relative;
|
||||||
bottom: 5px;
|
bottom: 5px;
|
||||||
|
height: 10%;
|
||||||
|
border-radius: 20px!important;
|
||||||
|
min-width: min(10%,100%) !important;
|
||||||
|
}
|
||||||
|
/* usage_display */
|
||||||
|
.insert_block {
|
||||||
|
position: relative;
|
||||||
|
bottom: 2px;
|
||||||
min-width: min(110px,100%) !important;
|
min-width: min(110px,100%) !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,20 +261,7 @@ textarea.svelte-1pie7s6 {
|
|||||||
font-size: 12px !important;
|
font-size: 12px !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* usage_display */
|
|
||||||
.insert_block {
|
|
||||||
position: relative;
|
|
||||||
margin: 0;
|
|
||||||
padding: .5em 1em;
|
|
||||||
box-shadow: var(--block-shadow);
|
|
||||||
border-width: var(--block-border-width);
|
|
||||||
border-color: var(--block-border-color);
|
|
||||||
border-radius: var(--block-radius);
|
|
||||||
background: var(--block-background-fill);
|
|
||||||
width: 100%;
|
|
||||||
line-height: var(--line-sm);
|
|
||||||
min-height: 2em;
|
|
||||||
}
|
|
||||||
#usage_display p, #usage_display span {
|
#usage_display p, #usage_display span {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
font-size: .85em;
|
font-size: .85em;
|
||||||
|
|||||||
@ -58,8 +58,8 @@ function gradioLoaded(mutations) {
|
|||||||
chat_txt = document.getElementById('chat_txt');
|
chat_txt = document.getElementById('chat_txt');
|
||||||
userInfoDiv = document.getElementById("user_info");
|
userInfoDiv = document.getElementById("user_info");
|
||||||
appTitleDiv = document.getElementById("app_title");
|
appTitleDiv = document.getElementById("app_title");
|
||||||
chatbot = document.querySelector('#main_chatbot');
|
chatbot = document.querySelector('#废弃');
|
||||||
chatbotWrap = document.querySelector('#main_chatbot > .wrap');
|
chatbotWrap = document.querySelector('#废弃 > .wrap');
|
||||||
apSwitch = document.querySelector('.apSwitch input[type="checkbox"]');
|
apSwitch = document.querySelector('.apSwitch input[type="checkbox"]');
|
||||||
|
|
||||||
if (loginUserForm) {
|
if (loginUserForm) {
|
||||||
@ -414,7 +414,7 @@ var mObserver = new MutationObserver(function (mutationsList) {
|
|||||||
for (var node of mmutation.addedNodes) {
|
for (var node of mmutation.addedNodes) {
|
||||||
if (node.nodeType === 1 && node.classList.contains('message') && node.getAttribute('data-testid') === 'bot') {
|
if (node.nodeType === 1 && node.classList.contains('message') && node.getAttribute('data-testid') === 'bot') {
|
||||||
saveHistoryHtml();
|
saveHistoryHtml();
|
||||||
document.querySelectorAll('#main_chatbot>.wrap>.message-wrap .message.bot').forEach(addChuanhuButton);
|
document.querySelectorAll('#废弃>.wrap>.message-wrap .message.bot').forEach(addChuanhuButton);
|
||||||
}
|
}
|
||||||
if (node.tagName === 'INPUT' && node.getAttribute('type') === 'range') {
|
if (node.tagName === 'INPUT' && node.getAttribute('type') === 'range') {
|
||||||
setSlider();
|
setSlider();
|
||||||
@ -423,7 +423,7 @@ var mObserver = new MutationObserver(function (mutationsList) {
|
|||||||
for (var node of mmutation.removedNodes) {
|
for (var node of mmutation.removedNodes) {
|
||||||
if (node.nodeType === 1 && node.classList.contains('message') && node.getAttribute('data-testid') === 'bot') {
|
if (node.nodeType === 1 && node.classList.contains('message') && node.getAttribute('data-testid') === 'bot') {
|
||||||
saveHistoryHtml();
|
saveHistoryHtml();
|
||||||
document.querySelectorAll('#main_chatbot>.wrap>.message-wrap .message.bot').forEach(addChuanhuButton);
|
document.querySelectorAll('#废弃>.wrap>.message-wrap .message.bot').forEach(addChuanhuButton);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (mmutation.type === 'attributes') {
|
} else if (mmutation.type === 'attributes') {
|
||||||
@ -433,7 +433,7 @@ var mObserver = new MutationObserver(function (mutationsList) {
|
|||||||
clearTimeout(timeoutId);
|
clearTimeout(timeoutId);
|
||||||
timeoutId = setTimeout(() => {
|
timeoutId = setTimeout(() => {
|
||||||
isThrottled = false;
|
isThrottled = false;
|
||||||
document.querySelectorAll('#main_chatbot>.wrap>.message-wrap .message.bot').forEach(addChuanhuButton);
|
document.querySelectorAll('#废弃>.wrap>.message-wrap .message.bot').forEach(addChuanhuButton);
|
||||||
saveHistoryHtml();
|
saveHistoryHtml();
|
||||||
}, 500);
|
}, 500);
|
||||||
}
|
}
|
||||||
@ -444,7 +444,7 @@ mObserver.observe(document.documentElement, { attributes: true, childList: true,
|
|||||||
|
|
||||||
var loadhistorytime = 0; // for debugging
|
var loadhistorytime = 0; // for debugging
|
||||||
function saveHistoryHtml() {
|
function saveHistoryHtml() {
|
||||||
var historyHtml = document.querySelector('#main_chatbot > .wrap');
|
var historyHtml = document.querySelector('#废弃 > .wrap');
|
||||||
localStorage.setItem('chatHistory', historyHtml.innerHTML);
|
localStorage.setItem('chatHistory', historyHtml.innerHTML);
|
||||||
// console.log("History Saved")
|
// console.log("History Saved")
|
||||||
historyLoaded = false;
|
historyLoaded = false;
|
||||||
|
|||||||
@ -1,7 +1,4 @@
|
|||||||
<div style="display: flex; justify-content: space-between;">
|
<div style="display: flex; justify-content: space-between;">
|
||||||
<span style="margin-top: 4px !important;">
|
|
||||||
{label}
|
|
||||||
</span>
|
|
||||||
<span>
|
<span>
|
||||||
<label class="apSwitch" for="checkbox">
|
<label class="apSwitch" for="checkbox">
|
||||||
<input type="checkbox" id="checkbox">
|
<input type="checkbox" id="checkbox">
|
||||||
|
|||||||
@ -649,8 +649,12 @@ def update_txt(self,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def txtx(f, q):
|
def get_html(filename):
|
||||||
return f
|
path = os.path.join(base_path, "docs/assets", "html", filename)
|
||||||
|
if os.path.exists(path):
|
||||||
|
with open(path, encoding="utf8") as file:
|
||||||
|
return file.read()
|
||||||
|
return ""
|
||||||
|
|
||||||
|
|
||||||
def git_log_list():
|
def git_log_list():
|
||||||
|
|||||||
25
theme.py
25
theme.py
@ -1,6 +1,6 @@
|
|||||||
import gradio as gr
|
import gradio as gr
|
||||||
from toolbox import get_conf
|
from toolbox import get_conf
|
||||||
CODE_HIGHLIGHT, ADD_WAIFU = get_conf('CODE_HIGHLIGHT', 'ADD_WAIFU')
|
CODE_HIGHLIGHT, ADD_WAIFU, ADD_CHUANHU = get_conf('CODE_HIGHLIGHT', 'ADD_WAIFU', 'ADD_CHUANHU')
|
||||||
# gradio可用颜色列表
|
# gradio可用颜色列表
|
||||||
# gr.themes.utils.colors.slate (石板色)
|
# gr.themes.utils.colors.slate (石板色)
|
||||||
# gr.themes.utils.colors.gray (灰色)
|
# gr.themes.utils.colors.gray (灰色)
|
||||||
@ -97,20 +97,27 @@ def adjust_theme():
|
|||||||
chatbot_code_background_color="*neutral_950",
|
chatbot_code_background_color="*neutral_950",
|
||||||
chatbot_code_background_color_dark="*neutral_950",
|
chatbot_code_background_color_dark="*neutral_950",
|
||||||
)
|
)
|
||||||
|
js = ''
|
||||||
|
if ADD_CHUANHU:
|
||||||
|
with open("./docs/assets/custom.js", "r", encoding="utf-8") as f, \
|
||||||
|
open("./docs/assets/external-scripts.js", "r", encoding="utf-8") as f1:
|
||||||
|
customJS = f.read()
|
||||||
|
externalScripts = f1.read()
|
||||||
|
js += f'<script>{customJS}</script><script async>{externalScripts}</script>'
|
||||||
# 添加一个萌萌的看板娘
|
# 添加一个萌萌的看板娘
|
||||||
if ADD_WAIFU:
|
if ADD_WAIFU:
|
||||||
js = """
|
js += """
|
||||||
<script src="file=docs/waifu_plugin/jquery.min.js"></script>
|
<script src="file=docs/waifu_plugin/jquery.min.js"></script>
|
||||||
<script src="file=docs/waifu_plugin/jquery-ui.min.js"></script>
|
<script src="file=docs/waifu_plugin/jquery-ui.min.js"></script>
|
||||||
<script src="file=docs/waifu_plugin/autoload.js"></script>
|
<script src="file=docs/waifu_plugin/autoload.js"></script>
|
||||||
"""
|
"""
|
||||||
gradio_original_template_fn = gr.routes.templates.TemplateResponse
|
gradio_original_template_fn = gr.routes.templates.TemplateResponse
|
||||||
def gradio_new_template_fn(*args, **kwargs):
|
def gradio_new_template_fn(*args, **kwargs):
|
||||||
res = gradio_original_template_fn(*args, **kwargs)
|
res = gradio_original_template_fn(*args, **kwargs)
|
||||||
res.body = res.body.replace(b'</html>', f'{js}</html>'.encode("utf8"))
|
res.body = res.body.replace(b'</html>', f'{js}</html>'.encode("utf8"))
|
||||||
res.init_headers()
|
res.init_headers()
|
||||||
return res
|
return res
|
||||||
gr.routes.templates.TemplateResponse = gradio_new_template_fn # override gradio template
|
gr.routes.templates.TemplateResponse = gradio_new_template_fn # override gradio template
|
||||||
except:
|
except:
|
||||||
set_theme = None
|
set_theme = None
|
||||||
print('gradio版本较旧, 不能自定义字体和颜色')
|
print('gradio版本较旧, 不能自定义字体和颜色')
|
||||||
|
|||||||
Reference in New Issue
Block a user