remove logging in gradios.py (#1699)

如果初始主题是HF社区主题,这里使用logging会导致程序不再写入日志(包括对话内容在内的任何记录),下载主题的日志输出和程序启动时的日志初始化有冲突。
This commit is contained in:
OREEkE 2024-04-11 14:15:12 +08:00 committed by GitHub
parent 2a003e8d49
commit 02b6f26b05
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,4 +1,3 @@
import logging
import os import os
import gradio as gr import gradio as gr
from toolbox import get_conf, ProxyNetworkActivate from toolbox import get_conf, ProxyNetworkActivate
@ -10,12 +9,15 @@ 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()
with ProxyNetworkActivate("Download_Gradio_Theme"): with ProxyNetworkActivate("Download_Gradio_Theme"):
logging.info("正在下载Gradio主题请稍等。") print("正在下载Gradio主题请稍等。")
if THEME.startswith("Huggingface-"): try:
THEME = THEME.lstrip("Huggingface-") if THEME.startswith("Huggingface-"):
if THEME.startswith("huggingface-"): THEME = THEME.lstrip("Huggingface-")
THEME = THEME.lstrip("huggingface-") if THEME.startswith("huggingface-"):
set_theme = set_theme.from_hub(THEME.lower()) THEME = THEME.lstrip("huggingface-")
set_theme = set_theme.from_hub(THEME.lower())
except:
print("下载Gradio主题时出现异常。")
return set_theme return set_theme
@ -23,13 +25,16 @@ 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"):
logging.info("正在下载Gradio主题请稍等。") print("正在下载Gradio主题请稍等。")
THEME = get_conf("THEME") try:
if THEME.startswith("Huggingface-"): THEME = get_conf("THEME")
THEME = THEME.lstrip("Huggingface-") if THEME.startswith("Huggingface-"):
if THEME.startswith("huggingface-"): THEME = THEME.lstrip("Huggingface-")
THEME = THEME.lstrip("huggingface-") if THEME.startswith("huggingface-"):
set_theme = set_theme.from_hub(THEME.lower()) THEME = THEME.lstrip("huggingface-")
set_theme = set_theme.from_hub(THEME.lower())
except:
print("下载Gradio主题时出现异常。")
from themes.common import get_common_html_javascript_code from themes.common import get_common_html_javascript_code
js = get_common_html_javascript_code() js = get_common_html_javascript_code()
@ -49,9 +54,7 @@ def adjust_theme():
) )
except Exception: except Exception:
set_theme = None set_theme = None
from toolbox import trimmed_format_exc print("gradio版本较旧, 不能自定义字体和颜色。")
logging.error("gradio版本较旧, 不能自定义字体和颜色:", trimmed_format_exc())
return set_theme return set_theme