Skip to content

Commit 2e8b400

Browse files
Merge pull request #12355 from AUTOMATIC1111/gradio-theme-cache
Gradio theme cache
2 parents ee96a6a + e9c591b commit 2e8b400

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

modules/shared.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,7 @@ def list_samplers():
551551
options_templates.update(options_section(('ui', "User interface"), {
552552
"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(),
553553
"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(),
554+
"gradio_themes_cache": OptionInfo(True, "Cache gradio themes locally").info("disable to update the selected Gradio theme"),
554555
"return_grid": OptionInfo(True, "Show grid in results for web"),
555556
"do_not_show_images": OptionInfo(False, "Do not show any images in results for web"),
556557
"send_seed": OptionInfo(True, "Send seed when sending prompt or image to other interface"),
@@ -865,13 +866,17 @@ def reload_gradio_theme(theme_name=None):
865866
gradio_theme = gr.themes.Default(**default_theme_args)
866867
else:
867868
try:
868-
gradio_theme = gr.themes.ThemeClass.from_hub(theme_name)
869+
theme_cache_path = os.path.join(script_path, 'tmp', 'gradio_themes', f'{theme_name.replace("/", "_")}.json')
870+
if opts.gradio_themes_cache and os.path.exists(theme_cache_path):
871+
gradio_theme = gr.themes.ThemeClass.load(theme_cache_path)
872+
else:
873+
gradio_theme = gr.themes.ThemeClass.from_hub(theme_name)
874+
gradio_theme.dump(theme_cache_path)
869875
except Exception as e:
870876
errors.display(e, "changing gradio theme")
871877
gradio_theme = gr.themes.Default(**default_theme_args)
872878

873879

874-
875880
class TotalTQDM:
876881
def __init__(self):
877882
self._tqdm = None

0 commit comments

Comments
 (0)