launch_utils.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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
  72. | str
  73. | Iterable[fonts.Font | str] = (
  74. fonts.GoogleFont("Quicksand"),
  75. "ui-sans-serif",
  76. "sans-serif",
  77. ),
  78. font_mono: fonts.Font
  79. | str
  80. | Iterable[fonts.Font | str] = (
  81. fonts.GoogleFont("IBM Plex Mono"),
  82. "ui-monospace",
  83. "monospace",
  84. ),
  85. ):
  86. super().__init__(
  87. primary_hue=primary_hue,
  88. secondary_hue=secondary_hue,
  89. neutral_hue=neutral_hue,
  90. spacing_size=spacing_size,
  91. radius_size=radius_size,
  92. text_size=text_size,
  93. font=font,
  94. font_mono=font_mono,
  95. )
  96. super().set(
  97. button_primary_background_fill="linear-gradient(90deg, *primary_300, *secondary_400)",
  98. button_primary_background_fill_hover="linear-gradient(90deg, *primary_200, *secondary_300)",
  99. button_primary_text_color="white",
  100. button_primary_background_fill_dark="linear-gradient(90deg, *primary_600, *secondary_800)",
  101. slider_color="*secondary_300",
  102. slider_color_dark="*secondary_600",
  103. block_title_text_weight="600",
  104. block_border_width="3px",
  105. block_shadow="*shadow_drop_lg",
  106. button_shadow="*shadow_drop_lg",
  107. button_small_padding="0px",
  108. button_large_padding="3px",
  109. )