diff --git a/config.py b/config.py index 1e91e39..2d57f09 100644 --- a/config.py +++ b/config.py @@ -43,7 +43,8 @@ API_URL_REDIRECT = {} DEFAULT_WORKER_NUM = 3 -# 色彩主题,可选 ["Default", "Chuanhu-Small-and-Beautiful", "High-Contrast"] +# 色彩主题, 可选 ["Default", "Chuanhu-Small-and-Beautiful", "High-Contrast"] +# 更多主题, 请查阅Gradio主题商店: https://huggingface.co/spaces/gradio/theme-gallery 可选 ["Gstaff/Xkcd", "NoCrypt/Miku", ...] THEME = "Default" diff --git a/main.py b/main.py index d475253..628d30b 100644 --- a/main.py +++ b/main.py @@ -123,6 +123,15 @@ def main(): max_length_sl = gr.Slider(minimum=256, maximum=8192, value=4096, step=1, interactive=True, label="Local LLM MaxLength",) checkboxes = gr.CheckboxGroup(["基础功能区", "函数插件区", "底部输入区", "输入清除键", "插件参数区"], value=["基础功能区", "函数插件区"], label="显示/隐藏功能区") md_dropdown = gr.Dropdown(AVAIL_LLM_MODELS, value=LLM_MODEL, label="更换LLM模型/请求源").style(container=False) + dark_mode_btn = gr.Button("Toggle Dark Mode ☀", variant="secondary").style(size="sm") + dark_mode_btn.click(None, None, None, _js="""() => { + if (document.querySelectorAll('.dark').length) { + document.querySelectorAll('.dark').forEach(el => el.classList.remove('dark')); + } else { + document.querySelector('body').classList.add('dark'); + } + }""", + ) gr.Markdown(description) with gr.Accordion("备选输入区", open=True, visible=False, elem_id="input-panel2") as area_input_secondary: with gr.Row(): diff --git a/themes/gradios.py b/themes/gradios.py new file mode 100644 index 0000000..8b661a5 --- /dev/null +++ b/themes/gradios.py @@ -0,0 +1,46 @@ +import gradio as gr +import logging +from toolbox import get_conf, ProxyNetworkActivate +CODE_HIGHLIGHT, ADD_WAIFU, LAYOUT = get_conf('CODE_HIGHLIGHT', 'ADD_WAIFU', 'LAYOUT') + +def adjust_theme(): + + try: + set_theme = gr.themes.ThemeClass() + with ProxyNetworkActivate(): + logging.info('正在下载Gradio主题,请稍等。') + THEME, = get_conf('THEME') + if THEME.startswith('Huggingface-'): THEME = THEME.lstrip('Huggingface-') + if THEME.startswith('huggingface-'): THEME = THEME.lstrip('huggingface-') + set_theme = set_theme.from_hub(THEME.lower()) + + if LAYOUT=="TOP-DOWN": + js = "" + else: + with open('themes/common.js', 'r', encoding='utf8') as f: + js = f"" + + # 添加一个萌萌的看板娘 + if ADD_WAIFU: + 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 + except Exception as e: + set_theme = None + from toolbox import trimmed_format_exc + logging.error('gradio版本较旧, 不能自定义字体和颜色:', trimmed_format_exc()) + return set_theme + +# with open("themes/default.css", "r", encoding="utf-8") as f: +# advanced_css = f.read() +with open("themes/common.css", "r", encoding="utf-8") as f: + advanced_css = f.read() diff --git a/themes/theme.py b/themes/theme.py index 5cba541..dbb8f1e 100644 --- a/themes/theme.py +++ b/themes/theme.py @@ -8,6 +8,9 @@ if THEME == 'Chuanhu-Small-and-Beautiful': elif THEME == 'High-Contrast': from .contrast import adjust_theme, advanced_css theme_declaration = "" +elif '/' in THEME: + from .gradios import adjust_theme, advanced_css + theme_declaration = "" else: from .default import adjust_theme, advanced_css theme_declaration = "" diff --git a/version b/version index 369a800..4f234c6 100644 --- a/version +++ b/version @@ -1,5 +1,5 @@ { - "version": 3.50, + "version": 3.51, "show_feature": true, - "new_feature": "支持插件分类! <-> 支持用户使用自然语言调度各个插件(虚空终端) ! <-> 改进UI,设计新主题 <-> 支持借助GROBID实现PDF高精度翻译 <-> 接入百度千帆平台和文心一言 <-> 接入阿里通义千问、讯飞星火、上海AI-Lab书生 <-> 优化一键升级 <-> 提高arxiv翻译速度和成功率" + "new_feature": "支持插件分类和更多UI皮肤外观 <-> 支持用户使用自然语言调度各个插件(虚空终端) ! <-> 改进UI,设计新主题 <-> 支持借助GROBID实现PDF高精度翻译 <-> 接入百度千帆平台和文心一言 <-> 接入阿里通义千问、讯飞星火、上海AI-Lab书生 <-> 优化一键升级 <-> 提高arxiv翻译速度和成功率" }