shared_gradio_themes.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. ]
  37. def reload_gradio_theme(theme_name=None):
  38. if not theme_name:
  39. theme_name = shared.opts.gradio_theme
  40. default_theme_args = dict(
  41. font=["Source Sans Pro", 'ui-sans-serif', 'system-ui', 'sans-serif'],
  42. font_mono=['IBM Plex Mono', 'ui-monospace', 'Consolas', 'monospace'],
  43. )
  44. if theme_name == "Default":
  45. shared.gradio_theme = gr.themes.Default(**default_theme_args)
  46. else:
  47. try:
  48. theme_cache_dir = os.path.join(script_path, 'tmp', 'gradio_themes')
  49. theme_cache_path = os.path.join(theme_cache_dir, f'{theme_name.replace("/", "_")}.json')
  50. if shared.opts.gradio_themes_cache and os.path.exists(theme_cache_path):
  51. shared.gradio_theme = gr.themes.ThemeClass.load(theme_cache_path)
  52. else:
  53. os.makedirs(theme_cache_dir, exist_ok=True)
  54. gradio_theme = gr.themes.ThemeClass.from_hub(theme_name)
  55. gradio_theme.dump(theme_cache_path)
  56. except Exception as e:
  57. errors.display(e, "changing gradio theme")
  58. shared.gradio_theme = gr.themes.Default(**default_theme_args)