launch_utils.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import importlib.util
  2. import os
  3. import subprocess
  4. import sys
  5. from functools import lru_cache
  6. from pathlib import Path
  7. from typing import Iterable
  8. import gradio as gr
  9. from gradio.themes.base import Base
  10. from gradio.themes.utils import colors, fonts, sizes
  11. GIT = (
  12. (Path(os.environ.get("GIT_HOME", "")) / "git").resolve()
  13. if sys.platform == "win32"
  14. else "git"
  15. )
  16. GIT = str(GIT)
  17. def is_module_installed(module_name: str) -> bool:
  18. spec = importlib.util.find_spec(module_name)
  19. return spec is not None
  20. @lru_cache()
  21. def commit_hash():
  22. try:
  23. return subprocess.check_output(
  24. [GIT, "log", "-1", "--format='%h %s'"], shell=False, encoding="utf8"
  25. ).strip()
  26. except Exception:
  27. return "<none>"
  28. def versions_html():
  29. import torch
  30. python_version = ".".join([str(x) for x in sys.version_info[0:3]])
  31. commit = commit_hash()
  32. hash = commit.strip("'").split(" ")[0]
  33. return f"""
  34. version: <a href="https://github.com/fishaudio/fish-speech/commit/{hash}">{hash}</a>
  35. &#x2000;•&#x2000;
  36. python: <span title="{sys.version}">{python_version}</span>
  37. &#x2000;•&#x2000;
  38. torch: {getattr(torch, '__long_version__',torch.__version__)}
  39. &#x2000;•&#x2000;
  40. gradio: {gr.__version__}
  41. &#x2000;•&#x2000;
  42. author: <a href="https://github.com/fishaudio">fishaudio</a>
  43. """
  44. def version_check(commit):
  45. try:
  46. import requests
  47. commits = requests.get(
  48. "https://api.github.com/repos/fishaudio/fish-speech/branches/main"
  49. ).json()
  50. if commit != "<none>" and commits["commit"]["sha"] != commit:
  51. print("--------------------------------------------------------")
  52. print("| You are not up to date with the most recent release. |")
  53. print("| Consider running `git pull` to update. |")
  54. print("--------------------------------------------------------")
  55. elif commits["commit"]["sha"] == commit:
  56. print("You are up to date with the most recent release.")
  57. else:
  58. print("Not a git clone, can't perform version check.")
  59. except Exception as e:
  60. print("version check failed", e)
  61. class Seafoam(Base):
  62. def __init__(
  63. self,
  64. *,
  65. primary_hue: colors.Color | str = colors.emerald,
  66. secondary_hue: colors.Color | str = colors.blue,
  67. neutral_hue: colors.Color | str = colors.blue,
  68. spacing_size: sizes.Size | str = sizes.spacing_md,
  69. radius_size: sizes.Size | str = sizes.radius_md,
  70. text_size: sizes.Size | str = sizes.text_lg,
  71. font: fonts.Font | str | Iterable[fonts.Font | str] = (
  72. fonts.GoogleFont("Quicksand"),
  73. "ui-sans-serif",
  74. "sans-serif",
  75. ),
  76. font_mono: fonts.Font | str | Iterable[fonts.Font | str] = (
  77. fonts.GoogleFont("IBM Plex Mono"),
  78. "ui-monospace",
  79. "monospace",
  80. ),
  81. ):
  82. super().__init__(
  83. primary_hue=primary_hue,
  84. secondary_hue=secondary_hue,
  85. neutral_hue=neutral_hue,
  86. spacing_size=spacing_size,
  87. radius_size=radius_size,
  88. text_size=text_size,
  89. font=font,
  90. font_mono=font_mono,
  91. )
  92. super().set(
  93. button_primary_background_fill="linear-gradient(90deg, *primary_300, *secondary_400)",
  94. button_primary_background_fill_hover="linear-gradient(90deg, *primary_200, *secondary_300)",
  95. button_primary_text_color="white",
  96. button_primary_background_fill_dark="linear-gradient(90deg, *primary_600, *secondary_800)",
  97. slider_color="*secondary_300",
  98. slider_color_dark="*secondary_600",
  99. block_title_text_weight="600",
  100. block_border_width="3px",
  101. block_shadow="*shadow_drop_lg",
  102. # button_shadow="*shadow_drop_lg",
  103. button_small_padding="0px",
  104. button_large_padding="3px",
  105. )