支持动态切换主题
This commit is contained in:
parent
e765ec1223
commit
2cad8e2694
7
main.py
7
main.py
@ -206,8 +206,11 @@ def main():
|
|||||||
md_dropdown.select(on_md_dropdown_changed, [md_dropdown], [chatbot] )
|
md_dropdown.select(on_md_dropdown_changed, [md_dropdown], [chatbot] )
|
||||||
|
|
||||||
def on_theme_dropdown_changed(theme, secret_css):
|
def on_theme_dropdown_changed(theme, secret_css):
|
||||||
adjust_theme, css_part1, _ = load_dynamic_theme(theme)
|
adjust_theme, css_part1, _, adjust_dynamic_theme = load_dynamic_theme(theme)
|
||||||
css_part2 = adjust_theme()._get_theme_css()
|
if adjust_dynamic_theme:
|
||||||
|
css_part2 = adjust_dynamic_theme._get_theme_css()
|
||||||
|
else:
|
||||||
|
css_part2 = adjust_theme()._get_theme_css()
|
||||||
return css_part2 + css_part1
|
return css_part2 + css_part1
|
||||||
|
|
||||||
theme_handle = theme_dropdown.select(on_theme_dropdown_changed, [theme_dropdown, secret_css], [secret_css])
|
theme_handle = theme_dropdown.select(on_theme_dropdown_changed, [theme_dropdown, secret_css], [secret_css])
|
||||||
|
@ -3,6 +3,15 @@ import logging
|
|||||||
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')
|
||||||
|
|
||||||
|
def dynamic_set_theme(THEME):
|
||||||
|
set_theme = gr.themes.ThemeClass()
|
||||||
|
with ProxyNetworkActivate():
|
||||||
|
logging.info('正在下载Gradio主题,请稍等。')
|
||||||
|
if THEME.startswith('Huggingface-'): THEME = THEME.lstrip('Huggingface-')
|
||||||
|
if THEME.startswith('huggingface-'): THEME = THEME.lstrip('huggingface-')
|
||||||
|
set_theme = set_theme.from_hub(THEME.lower())
|
||||||
|
return set_theme
|
||||||
|
|
||||||
def adjust_theme():
|
def adjust_theme():
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -3,6 +3,7 @@ from toolbox import get_conf
|
|||||||
THEME, = get_conf('THEME')
|
THEME, = get_conf('THEME')
|
||||||
|
|
||||||
def load_dynamic_theme(THEME):
|
def load_dynamic_theme(THEME):
|
||||||
|
adjust_dynamic_theme = None
|
||||||
if THEME == 'Chuanhu-Small-and-Beautiful':
|
if THEME == 'Chuanhu-Small-and-Beautiful':
|
||||||
from .green import adjust_theme, advanced_css
|
from .green import adjust_theme, advanced_css
|
||||||
theme_declaration = "<h2 align=\"center\" class=\"small\">[Chuanhu-Small-and-Beautiful主题]</h2>"
|
theme_declaration = "<h2 align=\"center\" class=\"small\">[Chuanhu-Small-and-Beautiful主题]</h2>"
|
||||||
@ -11,10 +12,12 @@ def load_dynamic_theme(THEME):
|
|||||||
theme_declaration = ""
|
theme_declaration = ""
|
||||||
elif '/' in THEME:
|
elif '/' in THEME:
|
||||||
from .gradios import adjust_theme, advanced_css
|
from .gradios import adjust_theme, advanced_css
|
||||||
|
from .gradios import dynamic_set_theme
|
||||||
|
adjust_dynamic_theme = dynamic_set_theme(THEME)
|
||||||
theme_declaration = ""
|
theme_declaration = ""
|
||||||
else:
|
else:
|
||||||
from .default import adjust_theme, advanced_css
|
from .default import adjust_theme, advanced_css
|
||||||
theme_declaration = ""
|
theme_declaration = ""
|
||||||
return adjust_theme, advanced_css, theme_declaration
|
return adjust_theme, advanced_css, theme_declaration, adjust_dynamic_theme
|
||||||
|
|
||||||
adjust_theme, advanced_css, theme_declaration = load_dynamic_theme(THEME)
|
adjust_theme, advanced_css, theme_declaration, _ = load_dynamic_theme(THEME)
|
Loading…
x
Reference in New Issue
Block a user