diff --git a/crazy_functional.py b/crazy_functional.py index 0f321f5..d823730 100644 --- a/crazy_functional.py +++ b/crazy_functional.py @@ -420,7 +420,7 @@ def get_crazy_functions(): try: from crazy_functions.辅助面试 import 辅助面试 function_plugins.update({ - "面试助手 [实时音频采集]": { + "实时音频采集": { "Color": "stop", "AsButton": True, "Function": HotReload(辅助面试) diff --git a/main.py b/main.py index 13c152f..eb422dd 100644 --- a/main.py +++ b/main.py @@ -8,8 +8,7 @@ def main(): # 建议您复制一个config_private.py放自己的秘密, 如API和代理网址, 避免不小心传github被别人看到 proxies, WEB_PORT, LLM_MODEL, CONCURRENT_COUNT, AUTHENTICATION, CHATBOT_HEIGHT, LAYOUT, AVAIL_LLM_MODELS, AUTO_CLEAR_TXT = \ get_conf('proxies', 'WEB_PORT', 'LLM_MODEL', 'CONCURRENT_COUNT', 'AUTHENTICATION', 'CHATBOT_HEIGHT', 'LAYOUT', 'AVAIL_LLM_MODELS', 'AUTO_CLEAR_TXT') - ENABLE_AUDIO, AUTO_CLEAR_TXT = \ - get_conf('ENABLE_AUDIO', 'AUTO_CLEAR_TXT') + ENABLE_AUDIO, AUTO_CLEAR_TXT = get_conf('ENABLE_AUDIO', 'AUTO_CLEAR_TXT') # 如果WEB_PORT是-1, 则随机选取WEB端口 PORT = find_free_port() if WEB_PORT <= 0 else WEB_PORT if not AUTHENTICATION: AUTHENTICATION = None @@ -189,7 +188,6 @@ def main(): # 终止按钮的回调函数注册 stopBtn.click(fn=None, inputs=None, outputs=None, cancels=cancel_handles) stopBtn2.click(fn=None, inputs=None, outputs=None, cancels=cancel_handles) - if ENABLE_AUDIO: from crazy_functions.live_audio.audio_io import RealtimeAudioDistribution rad = RealtimeAudioDistribution() @@ -203,7 +201,6 @@ def main(): return cookies demo.load(init_cookie, inputs=[cookies, chatbot], outputs=[cookies]) demo.load(lambda: 0, inputs=None, outputs=None, _js='()=>{ChatBotHeight();}') - # gradio的inbrowser触发不太稳定,回滚代码到原始的浏览器打开函数 def auto_opentab_delay(): diff --git a/theme/common.js b/theme/common.js new file mode 100644 index 0000000..dcdeb50 --- /dev/null +++ b/theme/common.js @@ -0,0 +1,47 @@ +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 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(); + setInterval(function() { + update_height_slow() + }, 50); // 每100毫秒执行一次 +} + +function get_elements() { + var chatbot = document.querySelector('#gpt-chatbot > div.wrap.svelte-18telvq'); + if (!chatbot) { + chatbot = document.querySelector('#gpt-chatbot'); + } + 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 }; +} \ No newline at end of file diff --git a/theme/default.py b/theme/default.py index c808a8b..936541e 100644 --- a/theme/default.py +++ b/theme/default.py @@ -1,33 +1,6 @@ -""" -gradio可用颜色列表 -gr.themes.utils.colors.slate (石板色) -gr.themes.utils.colors.gray (灰色) -gr.themes.utils.colors.zinc (锌色) -gr.themes.utils.colors.neutral (中性色) -gr.themes.utils.colors.stone (石头色) -gr.themes.utils.colors.red (红色) -gr.themes.utils.colors.orange (橙色) -gr.themes.utils.colors.amber (琥珀色) -gr.themes.utils.colors.yellow (黄色) -gr.themes.utils.colors.lime (酸橙色) -gr.themes.utils.colors.green (绿色) -gr.themes.utils.colors.emerald (祖母绿) -gr.themes.utils.colors.teal (青蓝色) -gr.themes.utils.colors.cyan (青色) -gr.themes.utils.colors.sky (天蓝色) -gr.themes.utils.colors.blue (蓝色) -gr.themes.utils.colors.indigo (靛蓝色) -gr.themes.utils.colors.violet (紫罗兰色) -gr.themes.utils.colors.purple (紫色) -gr.themes.utils.colors.fuchsia (洋红色) -gr.themes.utils.colors.pink (粉红色) -gr.themes.utils.colors.rose (玫瑰色) -""" - - import gradio as gr 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') def adjust_theme(): @@ -36,7 +9,8 @@ def adjust_theme(): set_theme = gr.themes.Default( primary_hue=gr.themes.utils.colors.orange, neutral_hue=gr.themes.utils.colors.gray, - font=["sans-serif", "Microsoft YaHei", "ui-sans-serif", "system-ui"], + font=["sans-serif", "Microsoft YaHei", "ui-sans-serif", "system-ui", + "sans-serif", gr.themes.utils.fonts.GoogleFont("Source Sans Pro")], font_mono=["ui-monospace", "Consolas", "monospace", gr.themes.utils.fonts.GoogleFont("IBM Plex Mono")]) set_theme.set( # Colors @@ -84,20 +58,26 @@ def adjust_theme(): button_cancel_text_color_dark="white", ) + if LAYOUT=="TOP-DOWN": + js = "" + else: + with open('theme/common.js', 'r', encoding='utf8') as f: + js = f"" + # 添加一个萌萌的看板娘 if ADD_WAIFU: - js = """ + js += """ """ - gradio_original_template_fn = gr.routes.templates.TemplateResponse - def gradio_new_template_fn(*args, **kwargs): - res = gradio_original_template_fn(*args, **kwargs) - res.body = res.body.replace(b'', f'{js}'.encode("utf8")) - res.init_headers() - return res - gr.routes.templates.TemplateResponse = gradio_new_template_fn # override gradio template + gradio_original_template_fn = gr.routes.templates.TemplateResponse + def gradio_new_template_fn(*args, **kwargs): + res = gradio_original_template_fn(*args, **kwargs) + res.body = res.body.replace(b'', f'{js}'.encode("utf8")) + res.init_headers() + return res + gr.routes.templates.TemplateResponse = gradio_new_template_fn # override gradio template except: set_theme = None print('gradio版本较旧, 不能自定义字体和颜色') diff --git a/theme/green.py b/theme/green.py index c3b0821..98ac776 100644 --- a/theme/green.py +++ b/theme/green.py @@ -1,6 +1,6 @@ import gradio as gr 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') def adjust_theme(): try: @@ -72,7 +72,14 @@ def adjust_theme(): chatbot_code_background_color="*neutral_950", chatbot_code_background_color_dark="*neutral_950", ) + js = '' + if LAYOUT=="TOP-DOWN": + js = "" + else: + with open('theme/common.js', 'r', encoding='utf8') as f: + js = f"" + # 添加一个萌萌的看板娘 if ADD_WAIFU: js += """