支持更多UI皮肤外观,加入暗色亮色切换键
This commit is contained in:
		
							parent
							
								
									e699b6b13f
								
							
						
					
					
						commit
						d495b73456
					
				@ -43,7 +43,8 @@ API_URL_REDIRECT = {}
 | 
				
			|||||||
DEFAULT_WORKER_NUM = 3
 | 
					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"
 | 
					THEME = "Default"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										9
									
								
								main.py
									
									
									
									
									
								
							
							
						
						
									
										9
									
								
								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",)
 | 
					                    max_length_sl = gr.Slider(minimum=256, maximum=8192, value=4096, step=1, interactive=True, label="Local LLM MaxLength",)
 | 
				
			||||||
                    checkboxes = gr.CheckboxGroup(["基础功能区", "函数插件区", "底部输入区", "输入清除键", "插件参数区"], value=["基础功能区", "函数插件区"], label="显示/隐藏功能区")
 | 
					                    checkboxes = gr.CheckboxGroup(["基础功能区", "函数插件区", "底部输入区", "输入清除键", "插件参数区"], value=["基础功能区", "函数插件区"], label="显示/隐藏功能区")
 | 
				
			||||||
                    md_dropdown = gr.Dropdown(AVAIL_LLM_MODELS, value=LLM_MODEL, label="更换LLM模型/请求源").style(container=False)
 | 
					                    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)
 | 
					                    gr.Markdown(description)
 | 
				
			||||||
                with gr.Accordion("备选输入区", open=True, visible=False, elem_id="input-panel2") as area_input_secondary:
 | 
					                with gr.Accordion("备选输入区", open=True, visible=False, elem_id="input-panel2") as area_input_secondary:
 | 
				
			||||||
                    with gr.Row():
 | 
					                    with gr.Row():
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										46
									
								
								themes/gradios.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								themes/gradios.py
									
									
									
									
									
										Normal file
									
								
							@ -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"<script>{f.read()}</script>"
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					        # 添加一个萌萌的看板娘
 | 
				
			||||||
 | 
					        if ADD_WAIFU:
 | 
				
			||||||
 | 
					            js += """
 | 
				
			||||||
 | 
					                <script src="file=docs/waifu_plugin/jquery.min.js"></script>
 | 
				
			||||||
 | 
					                <script src="file=docs/waifu_plugin/jquery-ui.min.js"></script>
 | 
				
			||||||
 | 
					                <script src="file=docs/waifu_plugin/autoload.js"></script>
 | 
				
			||||||
 | 
					            """
 | 
				
			||||||
 | 
					        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'</html>', f'{js}</html>'.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()
 | 
				
			||||||
@ -8,6 +8,9 @@ if THEME == 'Chuanhu-Small-and-Beautiful':
 | 
				
			|||||||
elif THEME == 'High-Contrast':
 | 
					elif THEME == 'High-Contrast':
 | 
				
			||||||
    from .contrast import adjust_theme, advanced_css
 | 
					    from .contrast import adjust_theme, advanced_css
 | 
				
			||||||
    theme_declaration = ""
 | 
					    theme_declaration = ""
 | 
				
			||||||
 | 
					elif '/' in THEME:
 | 
				
			||||||
 | 
					    from .gradios import adjust_theme, advanced_css
 | 
				
			||||||
 | 
					    theme_declaration = ""
 | 
				
			||||||
else:
 | 
					else:
 | 
				
			||||||
    from .default import adjust_theme, advanced_css
 | 
					    from .default import adjust_theme, advanced_css
 | 
				
			||||||
    theme_declaration = ""
 | 
					    theme_declaration = ""
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										4
									
								
								version
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								version
									
									
									
									
									
								
							@ -1,5 +1,5 @@
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
  "version": 3.50,
 | 
					  "version": 3.51,
 | 
				
			||||||
  "show_feature": true,
 | 
					  "show_feature": true,
 | 
				
			||||||
  "new_feature": "支持插件分类! <-> 支持用户使用自然语言调度各个插件(虚空终端) ! <-> 改进UI,设计新主题 <-> 支持借助GROBID实现PDF高精度翻译 <-> 接入百度千帆平台和文心一言 <-> 接入阿里通义千问、讯飞星火、上海AI-Lab书生 <-> 优化一键升级 <-> 提高arxiv翻译速度和成功率"
 | 
					  "new_feature": "支持插件分类和更多UI皮肤外观 <-> 支持用户使用自然语言调度各个插件(虚空终端) ! <-> 改进UI,设计新主题 <-> 支持借助GROBID实现PDF高精度翻译 <-> 接入百度千帆平台和文心一言 <-> 接入阿里通义千问、讯飞星火、上海AI-Lab书生 <-> 优化一键升级 <-> 提高arxiv翻译速度和成功率"
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user