Skip to content

Commit

Permalink
Generate config.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
Artrajz committed Oct 30, 2023
1 parent c9565ee commit d0e920f
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
/bert_vits2/bert/chinese-roberta-wwm-ext-large/pytorch_model.bin
/bert_vits2/bert/bert-base-japanese-v3/pytorch_model.bin
/vits/bert/prosody_model.pt
config.yml
2 changes: 2 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@

from tts_app import frontend, voice_api, auth, admin
from tts_app.auth.models import users
from utils.config_manager import global_config

app = Flask(__name__, template_folder=os.path.join(os.path.dirname(__file__), 'tts_app', 'templates'),
static_folder=os.path.join(os.path.dirname(__file__), 'tts_app', 'static'))

app.config.from_pyfile("config.py")
app.config.update(global_config)

login_manager = LoginManager()
login_manager.init_app(app)
Expand Down
5 changes: 4 additions & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@
API_KEY_ENABLED = False

# API_KEY is required for authentication
API_KEY = "api-key"
API_KEY = ""

# WTForms CSRF 保护
SECRET_KEY = ""

# logging_level:DEBUG/INFO/WARNING/ERROR/CRITICAL
LOGGING_LEVEL = "DEBUG"
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,4 @@ MarkupSafe==2.1.2
six==1.16.0
protobuf
tqdm
PyYAML
69 changes: 69 additions & 0 deletions utils/config_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import os
import shutil

import torch
import yaml

import config as default_config
from logger import logger

YAML_CONFIG_FILE = os.path.join(default_config.ABS_PATH, 'config.yml')

global_config = {}


# 修改表示和构造器的定义
def represent_torch_device(dumper, device_obj):
return dumper.represent_scalar('!torch.device', str(device_obj))


def construct_torch_device(loader, node):
device_str = loader.construct_scalar(node)
return torch.device(device_str)


yaml.add_representer(torch.device, represent_torch_device, Dumper=yaml.SafeDumper)
yaml.add_constructor('!torch.device', construct_torch_device, Loader=yaml.SafeLoader)


def load_yaml_config(filename):
with open(filename, 'r') as f:
yaml_config = yaml.safe_load(f)
logger.info(f"Loading yaml from {YAML_CONFIG_FILE}")
return yaml_config


def save_yaml_config(filename, data):
temp_filename = filename + '.tmp'
try:
with open(temp_filename, 'w') as f:
yaml.safe_dump(data, f)

shutil.move(temp_filename, filename)
logger.info(f"Saving yaml to {YAML_CONFIG_FILE}")
except Exception as e:
logger.error(f"Error while saving yaml: {e}")
if os.path.exists(temp_filename):
os.remove(temp_filename)



model_path = ["MODEL_LIST", "HUBERT_SOFT_MODEL", "DIMENSIONAL_EMOTION_NPY", "DIMENSIONAL_EMOTION_MODEL"]
default_parameter = ["ID", "FORMAT", "LANG", "LENGTH", "NOISE", "NOISEW", "MAX", "SDP_RATIO"]

if os.path.exists(YAML_CONFIG_FILE):
global_config.update(load_yaml_config(YAML_CONFIG_FILE))
else:
global_config.setdefault("model_path", {})
global_config.setdefault("default_parameter", {})

for key, value in vars(default_config).items():
if key.islower():
continue
if key in model_path:
global_config["model_path"][key.lower()] = value
elif key in default_parameter:
global_config["default_parameter"][key.lower()] = value
else:
global_config[key] = value
save_yaml_config(YAML_CONFIG_FILE, global_config)

0 comments on commit d0e920f

Please sign in to comment.