shared_gradio_themes.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import os
  2. import gradio as gr
  3. from modules import errors, shared
  4. from modules.paths_internal import script_path
  5. # https://huggingface.co/datasets/freddyaboulton/gradio-theme-subdomains/resolve/main/subdomains.json
  6. gradio_hf_hub_themes = [
  7. "gradio/base",
  8. "gradio/glass",
  9. "gradio/monochrome",
  10. "gradio/seafoam",
  11. "gradio/soft",
  12. "gradio/dracula_test",
  13. "abidlabs/dracula_test",
  14. "abidlabs/Lime",
  15. "abidlabs/pakistan",
  16. "Ama434/neutral-barlow",
  17. "dawood/microsoft_windows",
  18. "finlaymacklon/smooth_slate",
  19. "Franklisi/darkmode",
  20. "freddyaboulton/dracula_revamped",
  21. "freddyaboulton/test-blue",
  22. "gstaff/xkcd",
  23. "Insuz/Mocha",
  24. "Insuz/SimpleIndigo",
  25. "JohnSmith9982/small_and_pretty",
  26. "nota-ai/theme",
  27. "nuttea/Softblue",
  28. "ParityError/Anime",
  29. "reilnuud/polite",
  30. "remilia/Ghostly",
  31. "rottenlittlecreature/Moon_Goblin",
  32. "step-3-profit/Midnight-Deep",
  33. "Taithrah/Minimal",
  34. "ysharma/huggingface",
  35. "ysharma/steampunk",
  36. "NoCrypt/miku"
  37. ]
  38. def reload_gradio_theme(theme_name=None):
  39. if not theme_name:
  40. theme_name = shared.opts.gradio_theme
  41. default_theme_args = dict(
  42. font=["Source Sans Pro", 'ui-sans-serif', 'system-ui', 'sans-serif'],
  43. font_mono=['IBM Plex Mono', 'ui-monospace', 'Consolas', 'monospace'],
  44. )
  45. if theme_name == "Default":
  46. shared.gradio_theme = gr.themes.Default(**default_theme_args)
  47. else:
  48. try:
  49. theme_cache_dir = os.path.join(script_path, 'tmp', 'gradio_themes')
  50. theme_cache_path = os.path.join(theme_cache_dir, f'{theme_name.replace("/", "_")}.json')
  51. if shared.opts.gradio_themes_cache and os.path.exists(theme_cache_path):
  52. shared.gradio_theme = gr.themes.ThemeClass.load(theme_cache_path)
  53. else:
  54. os.makedirs(theme_cache_dir, exist_ok=True)
  55. shared.gradio_theme = gr.themes.ThemeClass.from_hub(theme_name)
  56. shared.gradio_theme.dump(theme_cache_path)
  57. except Exception as e:
  58. errors.display(e, "changing gradio theme")
  59. shared.gradio_theme = gr.themes.Default(**default_theme_args)
  60. # append additional values gradio_theme
  61. shared.gradio_theme.sd_webui_modal_lightbox_toolbar_opacity = shared.opts.sd_webui_modal_lightbox_toolbar_opacity
  62. shared.gradio_theme.sd_webui_modal_lightbox_icon_opacity = shared.opts.sd_webui_modal_lightbox_icon_opacity