修复看板娘不断分裂的BUG
This commit is contained in:
parent
7ca37c4831
commit
577d3d566b
@ -1,6 +1,8 @@
|
|||||||
|
import os
|
||||||
import gradio as gr
|
import gradio as gr
|
||||||
from toolbox import get_conf
|
from toolbox import get_conf
|
||||||
CODE_HIGHLIGHT, ADD_WAIFU, LAYOUT = get_conf('CODE_HIGHLIGHT', 'ADD_WAIFU', 'LAYOUT')
|
CODE_HIGHLIGHT, ADD_WAIFU, LAYOUT = get_conf('CODE_HIGHLIGHT', 'ADD_WAIFU', 'LAYOUT')
|
||||||
|
theme_dir = os.path.dirname(__file__)
|
||||||
|
|
||||||
def adjust_theme():
|
def adjust_theme():
|
||||||
|
|
||||||
@ -57,7 +59,7 @@ def adjust_theme():
|
|||||||
button_cancel_text_color_dark="white",
|
button_cancel_text_color_dark="white",
|
||||||
)
|
)
|
||||||
|
|
||||||
with open('themes/common.js', 'r', encoding='utf8') as f:
|
with open(os.path.join(theme_dir, 'common.js'), 'r', encoding='utf8') as f:
|
||||||
js = f"<script>{f.read()}</script>"
|
js = f"<script>{f.read()}</script>"
|
||||||
|
|
||||||
# 添加一个萌萌的看板娘
|
# 添加一个萌萌的看板娘
|
||||||
@ -67,7 +69,9 @@ def adjust_theme():
|
|||||||
<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
|
if not hasattr(gr, 'RawTemplateResponse'):
|
||||||
|
gr.RawTemplateResponse = gr.routes.templates.TemplateResponse
|
||||||
|
gradio_original_template_fn = gr.RawTemplateResponse
|
||||||
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"))
|
||||||
@ -79,7 +83,7 @@ def adjust_theme():
|
|||||||
print('gradio版本较旧, 不能自定义字体和颜色')
|
print('gradio版本较旧, 不能自定义字体和颜色')
|
||||||
return set_theme
|
return set_theme
|
||||||
|
|
||||||
with open("themes/contrast.css", "r", encoding="utf-8") as f:
|
with open(os.path.join(theme_dir, 'contrast.css'), "r", encoding="utf-8") as f:
|
||||||
advanced_css = f.read()
|
advanced_css = f.read()
|
||||||
with open("themes/common.css", "r", encoding="utf-8") as f:
|
with open(os.path.join(theme_dir, 'common.css'), "r", encoding="utf-8") as f:
|
||||||
advanced_css += f.read()
|
advanced_css += f.read()
|
||||||
|
@ -60,7 +60,7 @@ def adjust_theme():
|
|||||||
|
|
||||||
with open(os.path.join(theme_dir, 'common.js'), 'r', encoding='utf8') as f:
|
with open(os.path.join(theme_dir, 'common.js'), 'r', encoding='utf8') as f:
|
||||||
js = f"<script>{f.read()}</script>"
|
js = f"<script>{f.read()}</script>"
|
||||||
|
|
||||||
# 添加一个萌萌的看板娘
|
# 添加一个萌萌的看板娘
|
||||||
if ADD_WAIFU:
|
if ADD_WAIFU:
|
||||||
js += """
|
js += """
|
||||||
@ -68,7 +68,9 @@ def adjust_theme():
|
|||||||
<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
|
if not hasattr(gr, 'RawTemplateResponse'):
|
||||||
|
gr.RawTemplateResponse = gr.routes.templates.TemplateResponse
|
||||||
|
gradio_original_template_fn = gr.RawTemplateResponse
|
||||||
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"))
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
import gradio as gr
|
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
|
import gradio as gr
|
||||||
from toolbox import get_conf, ProxyNetworkActivate
|
from toolbox import get_conf, ProxyNetworkActivate
|
||||||
CODE_HIGHLIGHT, ADD_WAIFU, LAYOUT = get_conf('CODE_HIGHLIGHT', 'ADD_WAIFU', 'LAYOUT')
|
CODE_HIGHLIGHT, ADD_WAIFU, LAYOUT = get_conf('CODE_HIGHLIGHT', 'ADD_WAIFU', 'LAYOUT')
|
||||||
|
theme_dir = os.path.dirname(__file__)
|
||||||
|
|
||||||
def dynamic_set_theme(THEME):
|
def dynamic_set_theme(THEME):
|
||||||
set_theme = gr.themes.ThemeClass()
|
set_theme = gr.themes.ThemeClass()
|
||||||
@ -13,7 +15,6 @@ def dynamic_set_theme(THEME):
|
|||||||
return set_theme
|
return set_theme
|
||||||
|
|
||||||
def adjust_theme():
|
def adjust_theme():
|
||||||
|
|
||||||
try:
|
try:
|
||||||
set_theme = gr.themes.ThemeClass()
|
set_theme = gr.themes.ThemeClass()
|
||||||
with ProxyNetworkActivate('Download_Gradio_Theme'):
|
with ProxyNetworkActivate('Download_Gradio_Theme'):
|
||||||
@ -23,7 +24,7 @@ def adjust_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())
|
set_theme = set_theme.from_hub(THEME.lower())
|
||||||
|
|
||||||
with open('themes/common.js', 'r', encoding='utf8') as f:
|
with open(os.path.join(theme_dir, 'common.js'), 'r', encoding='utf8') as f:
|
||||||
js = f"<script>{f.read()}</script>"
|
js = f"<script>{f.read()}</script>"
|
||||||
|
|
||||||
# 添加一个萌萌的看板娘
|
# 添加一个萌萌的看板娘
|
||||||
@ -33,7 +34,9 @@ def adjust_theme():
|
|||||||
<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
|
if not hasattr(gr, 'RawTemplateResponse'):
|
||||||
|
gr.RawTemplateResponse = gr.routes.templates.TemplateResponse
|
||||||
|
gradio_original_template_fn = gr.RawTemplateResponse
|
||||||
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"))
|
||||||
@ -46,7 +49,5 @@ def adjust_theme():
|
|||||||
logging.error('gradio版本较旧, 不能自定义字体和颜色:', trimmed_format_exc())
|
logging.error('gradio版本较旧, 不能自定义字体和颜色:', trimmed_format_exc())
|
||||||
return set_theme
|
return set_theme
|
||||||
|
|
||||||
# with open("themes/default.css", "r", encoding="utf-8") as f:
|
with open(os.path.join(theme_dir, 'common.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()
|
advanced_css = f.read()
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
|
import os
|
||||||
import gradio as gr
|
import gradio as gr
|
||||||
from toolbox import get_conf
|
from toolbox import get_conf
|
||||||
CODE_HIGHLIGHT, ADD_WAIFU, LAYOUT = get_conf('CODE_HIGHLIGHT', 'ADD_WAIFU', 'LAYOUT')
|
CODE_HIGHLIGHT, ADD_WAIFU, LAYOUT = get_conf('CODE_HIGHLIGHT', 'ADD_WAIFU', 'LAYOUT')
|
||||||
|
theme_dir = os.path.dirname(__file__)
|
||||||
|
|
||||||
def adjust_theme():
|
def adjust_theme():
|
||||||
try:
|
try:
|
||||||
@ -73,7 +75,7 @@ def adjust_theme():
|
|||||||
chatbot_code_background_color_dark="*neutral_950",
|
chatbot_code_background_color_dark="*neutral_950",
|
||||||
)
|
)
|
||||||
|
|
||||||
with open('themes/common.js', 'r', encoding='utf8') as f:
|
with open(os.path.join(theme_dir, 'common.js'), 'r', encoding='utf8') as f:
|
||||||
js = f"<script>{f.read()}</script>"
|
js = f"<script>{f.read()}</script>"
|
||||||
|
|
||||||
# 添加一个萌萌的看板娘
|
# 添加一个萌萌的看板娘
|
||||||
@ -83,11 +85,13 @@ def adjust_theme():
|
|||||||
<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>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
with open('themes/green.js', 'r', encoding='utf8') as f:
|
with open(os.path.join(theme_dir, 'green.js'), 'r', encoding='utf8') as f:
|
||||||
js += f"<script>{f.read()}</script>"
|
js += f"<script>{f.read()}</script>"
|
||||||
|
|
||||||
gradio_original_template_fn = gr.routes.templates.TemplateResponse
|
if not hasattr(gr, 'RawTemplateResponse'):
|
||||||
|
gr.RawTemplateResponse = gr.routes.templates.TemplateResponse
|
||||||
|
gradio_original_template_fn = gr.RawTemplateResponse
|
||||||
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"))
|
||||||
@ -99,8 +103,7 @@ def adjust_theme():
|
|||||||
print('gradio版本较旧, 不能自定义字体和颜色')
|
print('gradio版本较旧, 不能自定义字体和颜色')
|
||||||
return set_theme
|
return set_theme
|
||||||
|
|
||||||
|
with open(os.path.join(theme_dir, 'green.css'), "r", encoding="utf-8") as f:
|
||||||
with open("themes/green.css", "r", encoding="utf-8") as f:
|
|
||||||
advanced_css = f.read()
|
advanced_css = f.read()
|
||||||
with open("themes/common.css", "r", encoding="utf-8") as f:
|
with open(os.path.join(theme_dir, 'common.css'), "r", encoding="utf-8") as f:
|
||||||
advanced_css += f.read()
|
advanced_css += f.read()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user