适配TOP-DOWN布局
This commit is contained in:
2
main.py
2
main.py
@ -58,7 +58,7 @@ def main():
|
|||||||
with gr_L1():
|
with gr_L1():
|
||||||
with gr_L2(scale=2, elem_id="gpt-chat"):
|
with gr_L2(scale=2, elem_id="gpt-chat"):
|
||||||
chatbot = gr.Chatbot(label=f"当前模型:{LLM_MODEL}", elem_id="gpt-chatbot")
|
chatbot = gr.Chatbot(label=f"当前模型:{LLM_MODEL}", elem_id="gpt-chatbot")
|
||||||
chatbot.style()
|
if LAYOUT == "TOP-DOWN": chatbot.style(height=CHATBOT_HEIGHT)
|
||||||
history = gr.State([])
|
history = gr.State([])
|
||||||
with gr_L2(scale=1, elem_id="gpt-panel"):
|
with gr_L2(scale=1, elem_id="gpt-panel"):
|
||||||
with gr.Accordion("输入区", open=True, elem_id="input-panel") as area_input_primary:
|
with gr.Accordion("输入区", open=True, elem_id="input-panel") as area_input_primary:
|
||||||
|
|||||||
96
theme.py
96
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, LAYOUT = get_conf('CODE_HIGHLIGHT', 'ADD_WAIFU', 'LAYOUT')
|
||||||
# gradio可用颜色列表
|
# gradio可用颜色列表
|
||||||
# gr.themes.utils.colors.slate (石板色)
|
# gr.themes.utils.colors.slate (石板色)
|
||||||
# gr.themes.utils.colors.gray (灰色)
|
# gr.themes.utils.colors.gray (灰色)
|
||||||
@ -82,59 +82,59 @@ def adjust_theme():
|
|||||||
button_cancel_text_color_dark="white",
|
button_cancel_text_color_dark="white",
|
||||||
)
|
)
|
||||||
|
|
||||||
# 别忘了layout的区别
|
# Layout = "LEFT-RIGHT"
|
||||||
js = """
|
js = """
|
||||||
<script>
|
<script>
|
||||||
|
function ChatBotHeight() {
|
||||||
|
function update_height(){
|
||||||
|
var { panel_height_target, chatbot_height, chatbot } = get_elements();
|
||||||
|
if (panel_height_target!=chatbot_height)
|
||||||
|
{
|
||||||
|
var pixelString = panel_height_target.toString() + 'px';
|
||||||
|
chatbot.style.maxHeight = pixelString; chatbot.style.height = pixelString;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function ChatBotHeight() {
|
function update_height_slow(){
|
||||||
|
var { panel_height_target, chatbot_height, chatbot } = get_elements();
|
||||||
|
if (panel_height_target!=chatbot_height)
|
||||||
|
{
|
||||||
|
new_panel_height = (panel_height_target - chatbot_height)*0.5 + chatbot_height;
|
||||||
|
if (Math.abs(new_panel_height - panel_height_target) < 10){
|
||||||
|
new_panel_height = panel_height_target;
|
||||||
|
}
|
||||||
|
console.log(chatbot_height, panel_height_target, new_panel_height);
|
||||||
|
var pixelString = new_panel_height.toString() + 'px';
|
||||||
|
chatbot.style.maxHeight = pixelString; chatbot.style.height = pixelString;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function update_height(){
|
update_height();
|
||||||
var { panel_height_target, chatbot_height, chatbot } = get_elements();
|
setInterval(function() {
|
||||||
if (panel_height_target!=chatbot_height)
|
update_height_slow()
|
||||||
{
|
}, 50); // 每100毫秒执行一次
|
||||||
var pixelString = panel_height_target.toString() + 'px';
|
|
||||||
chatbot.style.maxHeight = pixelString; chatbot.style.height = pixelString;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function update_height_slow(){
|
|
||||||
var { panel_height_target, chatbot_height, chatbot } = get_elements();
|
|
||||||
if (panel_height_target!=chatbot_height)
|
|
||||||
{
|
|
||||||
new_panel_height = (panel_height_target - chatbot_height)*0.5 + chatbot_height;
|
|
||||||
if (Math.abs(new_panel_height - panel_height_target) < 10){
|
|
||||||
new_panel_height = panel_height_target;
|
|
||||||
}
|
}
|
||||||
console.log(chatbot_height, panel_height_target, new_panel_height);
|
|
||||||
var pixelString = new_panel_height.toString() + 'px';
|
|
||||||
chatbot.style.maxHeight = pixelString; chatbot.style.height = pixelString;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
update_height();
|
function get_elements() {
|
||||||
setInterval(function() {
|
const chatbot = document.querySelector('#gpt-chatbot > div.wrap.svelte-18telvq');
|
||||||
update_height_slow()
|
const panel1 = document.querySelector('#input-panel');
|
||||||
}, 50); // 每100毫秒执行一次
|
const panel2 = document.querySelector('#basic-panel');
|
||||||
}
|
const panel3 = document.querySelector('#plugin-panel');
|
||||||
|
const panel4 = document.querySelector('#interact-panel');
|
||||||
|
const panel5 = document.querySelector('#input-panel2');
|
||||||
|
const panel_active = document.querySelector('#state-panel');
|
||||||
|
var panel_height_target = (20-panel_active.offsetHeight) + panel1.offsetHeight + panel2.offsetHeight + panel3.offsetHeight + panel4.offsetHeight + panel5.offsetHeight + 21;
|
||||||
|
var panel_height_target = parseInt(panel_height_target);
|
||||||
|
var chatbot_height = chatbot.style.height;
|
||||||
|
var chatbot_height = parseInt(chatbot_height);
|
||||||
|
return { panel_height_target, chatbot_height, chatbot };
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
"""
|
||||||
|
|
||||||
function get_elements() {
|
if LAYOUT=="TOP-DOWN":
|
||||||
const chatbot = document.querySelector('#gpt-chatbot > div.wrap.svelte-18telvq');
|
js = ""
|
||||||
const panel1 = document.querySelector('#input-panel');
|
|
||||||
const panel2 = document.querySelector('#basic-panel');
|
|
||||||
const panel3 = document.querySelector('#plugin-panel');
|
|
||||||
const panel4 = document.querySelector('#interact-panel');
|
|
||||||
const panel5 = document.querySelector('#input-panel2');
|
|
||||||
const panel_active = document.querySelector('#state-panel');
|
|
||||||
var panel_height_target = (20-panel_active.offsetHeight) + panel1.offsetHeight + panel2.offsetHeight + panel3.offsetHeight + panel4.offsetHeight + panel5.offsetHeight + 21;
|
|
||||||
var panel_height_target = parseInt(panel_height_target);
|
|
||||||
var chatbot_height = chatbot.style.height;
|
|
||||||
var chatbot_height = parseInt(chatbot_height);
|
|
||||||
return { panel_height_target, chatbot_height, chatbot };
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
"""
|
|
||||||
# 添加一个萌萌的看板娘
|
# 添加一个萌萌的看板娘
|
||||||
if ADD_WAIFU:
|
if ADD_WAIFU:
|
||||||
js += """
|
js += """
|
||||||
|
|||||||
Reference in New Issue
Block a user