Skip to content

Commit

Permalink
remove logging in gradios.py (binary-husky#1699)
Browse files Browse the repository at this point in the history
如果初始主题是HF社区主题,这里使用logging会导致程序不再写入日志(包括对话内容在内的任何记录),下载主题的日志输出和程序启动时的日志初始化有冲突。
  • Loading branch information
oreeke authored Apr 11, 2024
1 parent 2a003e8 commit 02b6f26
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions themes/gradios.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging
import os
import gradio as gr
from toolbox import get_conf, ProxyNetworkActivate
Expand All @@ -10,26 +9,32 @@
def dynamic_set_theme(THEME):
set_theme = gr.themes.ThemeClass()
with ProxyNetworkActivate("Download_Gradio_Theme"):
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())
print("正在下载Gradio主题,请稍等。")
try:
if THEME.startswith("Huggingface-"):
THEME = THEME.lstrip("Huggingface-")
if THEME.startswith("huggingface-"):
THEME = THEME.lstrip("huggingface-")
set_theme = set_theme.from_hub(THEME.lower())
except:
print("下载Gradio主题时出现异常。")
return set_theme


def adjust_theme():
try:
set_theme = gr.themes.ThemeClass()
with ProxyNetworkActivate("Download_Gradio_Theme"):
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())
print("正在下载Gradio主题,请稍等。")
try:
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())
except:
print("下载Gradio主题时出现异常。")

from themes.common import get_common_html_javascript_code
js = get_common_html_javascript_code()
Expand All @@ -49,9 +54,7 @@ def gradio_new_template_fn(*args, **kwargs):
)
except Exception:
set_theme = None
from toolbox import trimmed_format_exc

logging.error("gradio版本较旧, 不能自定义字体和颜色:", trimmed_format_exc())
print("gradio版本较旧, 不能自定义字体和颜色。")
return set_theme


Expand Down

0 comments on commit 02b6f26

Please sign in to comment.