Skip to content

Commit 35d82cb

Browse files
committed
Gradio theme cache
1 parent c6278c1 commit 35d82cb

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

modules/shared.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,7 @@ def list_samplers():
550550
options_templates.update(options_section(('ui', "User interface"), {
551551
"localization": OptionInfo("None", "Localization", gr.Dropdown, lambda: {"choices": ["None"] + list(localization.localizations.keys())}, refresh=lambda: localization.list_localizations(cmd_opts.localizations_dir)).needs_reload_ui(),
552552
"gradio_theme": OptionInfo("Default", "Gradio theme", ui_components.DropdownEditable, lambda: {"choices": ["Default"] + gradio_hf_hub_themes}).info("you can also manually enter any of themes from the <a href='https://huggingface.co/spaces/gradio/theme-gallery'>gallery</a>.").needs_reload_ui(),
553+
"re_download_theme": OptionInfo(False, "Re-download the selected Gradio theme"),
553554
"return_grid": OptionInfo(True, "Show grid in results for web"),
554555
"do_not_show_images": OptionInfo(False, "Do not show any images in results for web"),
555556
"send_seed": OptionInfo(True, "Send seed when sending prompt or image to other interface"),
@@ -863,13 +864,17 @@ def reload_gradio_theme(theme_name=None):
863864
gradio_theme = gr.themes.Default(**default_theme_args)
864865
else:
865866
try:
866-
gradio_theme = gr.themes.ThemeClass.from_hub(theme_name)
867+
theme_cache_path = os.path.join(script_path, 'tmp', 'gradio_themes', f'{theme_name.replace("/", "_")}.json')
868+
if not opts.re_download_theme and os.path.exists(theme_cache_path):
869+
gradio_theme = gr.themes.base.ThemeClass().load(theme_cache_path)
870+
else:
871+
gradio_theme = gr.themes.ThemeClass.from_hub(theme_name)
872+
gradio_theme.dump(theme_cache_path)
867873
except Exception as e:
868874
errors.display(e, "changing gradio theme")
869875
gradio_theme = gr.themes.Default(**default_theme_args)
870876

871877

872-
873878
class TotalTQDM:
874879
def __init__(self):
875880
self._tqdm = None

0 commit comments

Comments
 (0)