From d495b73456eb504d4cf995ee910ce387d28e4600 Mon Sep 17 00:00:00 2001
From: qingxu fu <505030475@qq.com>
Date: Mon, 11 Sep 2023 22:55:32 +0800
Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=9B=B4=E5=A4=9AUI=E7=9A=AE?=
=?UTF-8?q?=E8=82=A4=E5=A4=96=E8=A7=82=EF=BC=8C=E5=8A=A0=E5=85=A5=E6=9A=97?=
=?UTF-8?q?=E8=89=B2=E4=BA=AE=E8=89=B2=E5=88=87=E6=8D=A2=E9=94=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
config.py | 3 ++-
main.py | 9 +++++++++
themes/gradios.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++
themes/theme.py | 3 +++
version | 4 ++--
5 files changed, 62 insertions(+), 3 deletions(-)
create mode 100644 themes/gradios.py
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'