Skip to content

Commit

Permalink
🎨 improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
zhzLuke96 committed Jun 9, 2024
1 parent 50d354c commit 317951e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion data/load_json_spk.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
from modules.speaker import speaker_mgr


# 出处: https://github.com/2noise/ChatTTS/issues/238
data = json.load(open("./data/slct_voice_240605.json", "r"))

print("load speakers: ", len(data))
Expand Down
15 changes: 15 additions & 0 deletions modules/utils/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,25 @@
import os
import subprocess


from modules.utils import constants

# 用于判断是否在hf spaces
try:
import spaces
except:
spaces = None

git = os.environ.get("GIT", "git")

in_hf_spaces = spaces is not None


@lru_cache()
def commit_hash():
try:
if in_hf_spaces:
return "<hf>"
return subprocess.check_output(
[git, "-C", constants.ROOT_DIR, "rev-parse", "HEAD"],
shell=False,
Expand All @@ -22,6 +33,8 @@ def commit_hash():
@lru_cache()
def git_tag():
try:
if in_hf_spaces:
return "<hf>"
return subprocess.check_output(
[git, "-C", constants.ROOT_DIR, "describe", "--tags"],
shell=False,
Expand All @@ -44,6 +57,8 @@ def git_tag():
@lru_cache()
def branch_name():
try:
if in_hf_spaces:
return "<hf>"
return subprocess.check_output(
[git, "-C", constants.ROOT_DIR, "rev-parse", "--abbrev-ref", "HEAD"],
shell=False,
Expand Down
12 changes: 10 additions & 2 deletions modules/webui/localization.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import json
import os
import gradio as gr
import logging

logger = logging.getLogger(__name__)

current_translation = {}
localization_root = os.path.join(
Expand All @@ -24,9 +26,15 @@ def localization_js(filename):
assert isinstance(v, str) or isinstance(
v, list
), f"Value for key {k} is not a string or list"

logger.info(f"Loaded localization file {full_name}")
except Exception as e:
print(str(e))
print(f"Failed to load localization file {full_name}")
logger.warning(str(e))
logger.warning(f"Failed to load localization file {full_name}")
else:
logger.warning(f"Localization file {full_name} does not exist")
else:
logger.warning(f"Localization file {filename} is not a string")

# current_translation = {k: 'XXX' for k in current_translation.keys()} # use this to see if all texts are covered

Expand Down

0 comments on commit 317951e

Please sign in to comment.