launch_utils.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import os
  2. import subprocess
  3. import sys
  4. from functools import lru_cache
  5. from pathlib import Path
  6. from typing import Iterable
  7. import gradio as gr
  8. from gradio.themes.base import Base
  9. from gradio.themes.utils import colors, fonts, sizes
  10. GIT = (
  11. (Path(os.environ.get("GIT_HOME", "")) / "git").resolve()
  12. if sys.platform == "win32"
  13. else "git"
  14. )
  15. GIT = str(GIT)
  16. @lru_cache()
  17. def commit_hash():
  18. try:
  19. return subprocess.check_output(
  20. [GIT, "log", "-1", "--format='%h %s'"], shell=False, encoding="utf8"
  21. ).strip()
  22. except Exception:
  23. return "<none>"
  24. def versions_html():
  25. import torch
  26. python_version = ".".join([str(x) for x in sys.version_info[0:3]])
  27. commit = commit_hash()
  28. hash = commit.strip("'").split(" ")[0]
  29. return f"""
  30. version: <a href="https://github.com/AnyaCoder/fish-speech/commit/{hash}">{hash}</a>
  31. &#x2000;•&#x2000;
  32. python: <span title="{sys.version}">{python_version}</span>
  33. &#x2000;•&#x2000;
  34. torch: {getattr(torch, '__long_version__',torch.__version__)}
  35. &#x2000;•&#x2000;
  36. gradio: {gr.__version__}
  37. &#x2000;•&#x2000;
  38. author: <a href="https://github.com/AnyaCoder">laziman/AnyaCoder</a>
  39. """
  40. def version_check(commit):
  41. try:
  42. import requests
  43. commits = requests.get(
  44. "https://api.github.com/repos/AnyaCoder/fish-speech/branches/main"
  45. ).json()
  46. if commit != "<none>" and commits["commit"]["sha"] != commit:
  47. print("--------------------------------------------------------")
  48. print("| You are not up to date with the most recent release. |")
  49. print("| Consider running `git pull` to update. |")
  50. print("--------------------------------------------------------")
  51. elif commits["commit"]["sha"] == commit:
  52. print("You are up to date with the most recent release.")
  53. else:
  54. print("Not a git clone, can't perform version check.")
  55. except Exception as e:
  56. print("version check failed", e)
  57. class Seafoam(Base):
  58. def __init__(
  59. self,
  60. *,
  61. primary_hue: colors.Color | str = colors.emerald,
  62. secondary_hue: colors.Color | str = colors.blue,
  63. neutral_hue: colors.Color | str = colors.blue,
  64. spacing_size: sizes.Size | str = sizes.spacing_md,
  65. radius_size: sizes.Size | str = sizes.radius_md,
  66. text_size: sizes.Size | str = sizes.text_lg,
  67. font: fonts.Font
  68. | str
  69. | Iterable[fonts.Font | str] = (
  70. fonts.GoogleFont("Quicksand"),
  71. "ui-sans-serif",
  72. "sans-serif",
  73. ),
  74. font_mono: fonts.Font
  75. | str
  76. | 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. )