Spaces:
Runtime error
Runtime error
zhzluke96 commited on
Commit ·
4c19a5a
1
Parent(s): d8e7d56
update
Browse filesFiles changed (6)
- modules/api/impl/ping_api.py+7-1
- modules/api/utils.py+1-1
- modules/config.py+16
- modules/utils/constants.pyAdded+13
- modules/utils/git.pyAdded+59
- webui.py+26-5
12345678981011121314from modules.api import utils as api_utilsfrom modules.api.Api import APIManager
from modules import config
def setup(app: APIManager): @app.get("/v1/ping", response_model=api_utils.BaseResponse) async def ping(): return {"message": "ok", "data": "pong"} return api_utils.success_response("pong")
@app.get("/v1/versions", response_model=api_utils.BaseResponse) async def get_versions(): return api_utils.success_response(config.versions.to_dict())35 unmodified lines363738393940414235 unmodified lines }
def success_response(data: Any, message: str = "Success") -> BaseResponse:def success_response(data: Any, message: str = "ok") -> BaseResponse: return BaseResponse(message=message, data=data)
123456789101112131415161718192021import sys
import torchfrom modules.utils.JsonObject import JsonObject
from modules.utils import git
runtime_env_vars = JsonObject({})
api = None
versions = JsonObject( { "python_version": ".".join([str(x) for x in sys.version_info[0:3]]), "torch_version": getattr(torch, "__long_version__", torch.__version__), # "gradio_version":gr.__version__, "git_tag": git.git_tag(), "git_branch": git.branch_name(), "git_commit": git.commit_hash(), })12345678910111213import os
cwd = os.getcwd()utils_path = os.path.dirname(os.path.realpath(__file__))modules_path = os.path.dirname(utils_path)
ROOT_DIR = os.path.dirname(modules_path)DATA_DIR = os.path.join(ROOT_DIR, "data")
MODELS_DIR = os.path.join(ROOT_DIR, "models")
speakers_dir = os.path.join(DATA_DIR, "speakers")1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859from functools import lru_cacheimport osimport subprocess
from modules.utils import constants
git = os.environ.get("GIT", "git")
@lru_cache()def commit_hash(): try: return subprocess.check_output( [git, "-C", constants.ROOT_DIR, "rev-parse", "HEAD"], shell=False, encoding="utf8", ).strip() except Exception: return "<none>"
@lru_cache()def git_tag(): try: return subprocess.check_output( [git, "-C", constants.ROOT_DIR, "describe", "--tags"], shell=False, encoding="utf8", ).strip() except Exception: try:
changelog_md = os.path.join( os.path.dirname(os.path.dirname(__file__)), "CHANGELOG.md" ) with open(changelog_md, "r", encoding="utf-8") as file: line = next((line.strip() for line in file if line.strip()), "<none>") line = line.replace("## ", "") return line except Exception: return "<none>"
@lru_cache()def branch_name(): try: return subprocess.check_output( [git, "-C", constants.ROOT_DIR, "rev-parse", "--abbrev-ref", "HEAD"], shell=False, encoding="utf8", ).strip() except Exception: return "<none>"
if __name__ == "__main__": print(commit_hash()) print(git_tag()) print(branch_name())12 unmodified lines13141516171819202121222324157 unmodified lines182183184185185186187188418 unmodified lines607608609610611612613614166 unmodified lines78178278378478578678778878979079179279379479579679779879980080180280380421 unmodified lines82682782882983083183283383411 unmodified lines84684784882682782884985085185212 unmodified lines
import osimport loggingimport sys
import numpy as np
from modules.devices import devicesfrom modules.synthesize_audio import synthesize_audiofrom modules.utils.cache import conditional_cache
logging.basicConfig( level=os.getenv("LOG_LEVEL", "INFO"),157 unmodified linesdef read_local_readme(): with open("README.md", "r", encoding="utf-8") as file: content = file.read() content = content[content.index("# 🗣️ ChatTTS-Forge") :] content = content[content.index("# ") :] return content
418 unmodified lines return ssml_input
# NOTE: 这个其实是需要GPU的...但是spaces会自动卸载,所以不太好使,具体处理在text_normalize中兼容# @spaces.GPUdef split_long_text(long_text_input): spliter = SentenceSplitter(webui_config["spliter_threshold"]) sentences = spliter.parse(long_text_input)166 unmodified lines gr.Markdown(readme_content)
def create_app_footer(): gradio_version = gr.__version__ git_tag = config.versions.git_tag git_commit = config.versions.git_commit git_branch = config.versions.git_branch python_version = config.versions.python_version torch_version = config.versions.torch_version
config.versions.gradio_version = gradio_version
gr.Markdown( f"""🍦 [ChatTTS-Forge](https://github.com/lenML/ChatTTS-Forge)version: [{git_tag}](https://github.com/lenML/ChatTTS-Forge/commit/{git_commit}) | branch: `{git_branch}` | python: `{python_version}` | torch: `{torch_version}` """ )
def create_interface():
js_func = """21 unmodified lines #input_title div.eta-bar { display: none !important; transform: none !important; } footer { display: none !important; } </style> """
11 unmodified lines with gr.TabItem("README"): create_readme_tab()
gr.Markdown( "此项目基于 [ChatTTS-Forge](https://github.com/lenML/ChatTTS-Forge) " ) create_app_footer() return demo
modules/api/impl/ping_api.py+7-1
modules/api/utils.py+1-1
modules/config.py+16
modules/utils/constants.pyAdded+13
modules/utils/git.pyAdded+59
webui.py+26-5