zhzluke96 commited on
Commit
4c19a5a
1 Parent(s): d8e7d56
modules/api/impl/ping_api.py CHANGED
@@ -1,8 +1,14 @@
1
  from modules.api import utils as api_utils
2
  from modules.api.Api import APIManager
3
 
 
 
4
 
5
  def setup(app: APIManager):
6
  @app.get("/v1/ping", response_model=api_utils.BaseResponse)
7
  async def ping():
8
- return {"message": "ok", "data": "pong"}
 
 
 
 
 
1
  from modules.api import utils as api_utils
2
  from modules.api.Api import APIManager
3
 
4
+ from modules import config
5
+
6
 
7
  def setup(app: APIManager):
8
  @app.get("/v1/ping", response_model=api_utils.BaseResponse)
9
  async def ping():
10
+ return api_utils.success_response("pong")
11
+
12
+ @app.get("/v1/versions", response_model=api_utils.BaseResponse)
13
+ async def get_versions():
14
+ return api_utils.success_response(config.versions.to_dict())
modules/api/utils.py CHANGED
@@ -36,7 +36,7 @@ class BaseResponse(BaseModel):
36
  }
37
 
38
 
39
- def success_response(data: Any, message: str = "Success") -> BaseResponse:
40
  return BaseResponse(message=message, data=data)
41
 
42
 
 
36
  }
37
 
38
 
39
+ def success_response(data: Any, message: str = "ok") -> BaseResponse:
40
  return BaseResponse(message=message, data=data)
41
 
42
 
modules/config.py CHANGED
@@ -1,5 +1,21 @@
 
 
 
1
  from modules.utils.JsonObject import JsonObject
2
 
 
 
3
  runtime_env_vars = JsonObject({})
4
 
5
  api = None
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys
2
+
3
+ import torch
4
  from modules.utils.JsonObject import JsonObject
5
 
6
+ from modules.utils import git
7
+
8
  runtime_env_vars = JsonObject({})
9
 
10
  api = None
11
+
12
+ versions = JsonObject(
13
+ {
14
+ "python_version": ".".join([str(x) for x in sys.version_info[0:3]]),
15
+ "torch_version": getattr(torch, "__long_version__", torch.__version__),
16
+ # "gradio_version":gr.__version__,
17
+ "git_tag": git.git_tag(),
18
+ "git_branch": git.branch_name(),
19
+ "git_commit": git.commit_hash(),
20
+ }
21
+ )
modules/utils/constants.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+
4
+ cwd = os.getcwd()
5
+ utils_path = os.path.dirname(os.path.realpath(__file__))
6
+ modules_path = os.path.dirname(utils_path)
7
+
8
+ ROOT_DIR = os.path.dirname(modules_path)
9
+ DATA_DIR = os.path.join(ROOT_DIR, "data")
10
+
11
+ MODELS_DIR = os.path.join(ROOT_DIR, "models")
12
+
13
+ speakers_dir = os.path.join(DATA_DIR, "speakers")
modules/utils/git.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from functools import lru_cache
2
+ import os
3
+ import subprocess
4
+
5
+ from modules.utils import constants
6
+
7
+ git = os.environ.get("GIT", "git")
8
+
9
+
10
+ @lru_cache()
11
+ def commit_hash():
12
+ try:
13
+ return subprocess.check_output(
14
+ [git, "-C", constants.ROOT_DIR, "rev-parse", "HEAD"],
15
+ shell=False,
16
+ encoding="utf8",
17
+ ).strip()
18
+ except Exception:
19
+ return "<none>"
20
+
21
+
22
+ @lru_cache()
23
+ def git_tag():
24
+ try:
25
+ return subprocess.check_output(
26
+ [git, "-C", constants.ROOT_DIR, "describe", "--tags"],
27
+ shell=False,
28
+ encoding="utf8",
29
+ ).strip()
30
+ except Exception:
31
+ try:
32
+
33
+ changelog_md = os.path.join(
34
+ os.path.dirname(os.path.dirname(__file__)), "CHANGELOG.md"
35
+ )
36
+ with open(changelog_md, "r", encoding="utf-8") as file:
37
+ line = next((line.strip() for line in file if line.strip()), "<none>")
38
+ line = line.replace("## ", "")
39
+ return line
40
+ except Exception:
41
+ return "<none>"
42
+
43
+
44
+ @lru_cache()
45
+ def branch_name():
46
+ try:
47
+ return subprocess.check_output(
48
+ [git, "-C", constants.ROOT_DIR, "rev-parse", "--abbrev-ref", "HEAD"],
49
+ shell=False,
50
+ encoding="utf8",
51
+ ).strip()
52
+ except Exception:
53
+ return "<none>"
54
+
55
+
56
+ if __name__ == "__main__":
57
+ print(commit_hash())
58
+ print(git_tag())
59
+ print(branch_name())
webui.py CHANGED
@@ -13,12 +13,12 @@ except:
13
 
14
  import os
15
  import logging
 
16
 
17
  import numpy as np
18
 
19
  from modules.devices import devices
20
  from modules.synthesize_audio import synthesize_audio
21
- from modules.utils.cache import conditional_cache
22
 
23
  logging.basicConfig(
24
  level=os.getenv("LOG_LEVEL", "INFO"),
@@ -182,7 +182,7 @@ def refine_text(text: str, prompt: str):
182
  def read_local_readme():
183
  with open("README.md", "r", encoding="utf-8") as file:
184
  content = file.read()
185
- content = content[content.index("# 🗣️ ChatTTS-Forge") :]
186
  return content
187
 
188
 
@@ -607,6 +607,8 @@ def create_ssml_interface():
607
  return ssml_input
608
 
609
 
 
 
610
  def split_long_text(long_text_input):
611
  spliter = SentenceSplitter(webui_config["spliter_threshold"])
612
  sentences = spliter.parse(long_text_input)
@@ -779,6 +781,24 @@ def create_readme_tab():
779
  gr.Markdown(readme_content)
780
 
781
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
782
  def create_interface():
783
 
784
  js_func = """
@@ -806,6 +826,9 @@ def create_interface():
806
  #input_title div.eta-bar {
807
  display: none !important; transform: none !important;
808
  }
 
 
 
809
  </style>
810
  """
811
 
@@ -823,9 +846,7 @@ def create_interface():
823
  with gr.TabItem("README"):
824
  create_readme_tab()
825
 
826
- gr.Markdown(
827
- "此项目基于 [ChatTTS-Forge](https://github.com/lenML/ChatTTS-Forge) "
828
- )
829
  return demo
830
 
831
 
 
13
 
14
  import os
15
  import logging
16
+ import sys
17
 
18
  import numpy as np
19
 
20
  from modules.devices import devices
21
  from modules.synthesize_audio import synthesize_audio
 
22
 
23
  logging.basicConfig(
24
  level=os.getenv("LOG_LEVEL", "INFO"),
 
182
  def read_local_readme():
183
  with open("README.md", "r", encoding="utf-8") as file:
184
  content = file.read()
185
+ content = content[content.index("# ") :]
186
  return content
187
 
188
 
 
607
  return ssml_input
608
 
609
 
610
+ # NOTE: 这个其实是需要GPU的...但是spaces会自动卸载,所以不太好使,具体处理在text_normalize中兼容
611
+ # @spaces.GPU
612
  def split_long_text(long_text_input):
613
  spliter = SentenceSplitter(webui_config["spliter_threshold"])
614
  sentences = spliter.parse(long_text_input)
 
781
  gr.Markdown(readme_content)
782
 
783
 
784
+ def create_app_footer():
785
+ gradio_version = gr.__version__
786
+ git_tag = config.versions.git_tag
787
+ git_commit = config.versions.git_commit
788
+ git_branch = config.versions.git_branch
789
+ python_version = config.versions.python_version
790
+ torch_version = config.versions.torch_version
791
+
792
+ config.versions.gradio_version = gradio_version
793
+
794
+ gr.Markdown(
795
+ f"""
796
+ 🍦 [ChatTTS-Forge](https://github.com/lenML/ChatTTS-Forge)
797
+ version: [{git_tag}](https://github.com/lenML/ChatTTS-Forge/commit/{git_commit}) | branch: `{git_branch}` | python: `{python_version}` | torch: `{torch_version}`
798
+ """
799
+ )
800
+
801
+
802
  def create_interface():
803
 
804
  js_func = """
 
826
  #input_title div.eta-bar {
827
  display: none !important; transform: none !important;
828
  }
829
+ footer {
830
+ display: none !important;
831
+ }
832
  </style>
833
  """
834
 
 
846
  with gr.TabItem("README"):
847
  create_readme_tab()
848
 
849
+ create_app_footer()
 
 
850
  return demo
851
 
852