From 1546bd4ec525c211595e3939a197a5516b239859 Mon Sep 17 00:00:00 2001 From: litagin02 Date: Tue, 2 Jan 2024 22:58:17 +0900 Subject: [PATCH] Ensure ascii false for json dump, and fix bug --- default_style.py | 2 +- webui_merge.py | 28 ++++++++++++++-------------- webui_style_vectors.py | 4 ++-- webui_train.py | 2 +- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/default_style.py b/default_style.py index ced093c..9198ca8 100644 --- a/default_style.py +++ b/default_style.py @@ -12,7 +12,7 @@ def set_style_config(json_path, output_path): json_dict["data"]["num_styles"] = 1 json_dict["data"]["style2id"] = {DEFAULT_STYLE: 0} with open(output_path, "w", encoding="utf-8") as f: - json.dump(json_dict, f, indent=2) + json.dump(json_dict, f, indent=2, ensure_ascii=False) logger.info(f"Save style config (only {DEFAULT_STYLE}) to {output_path}") diff --git a/webui_merge.py b/webui_merge.py index 39c31e7..2635c5a 100644 --- a/webui_merge.py +++ b/webui_merge.py @@ -41,17 +41,17 @@ def merge_style(model_name_a, model_name_b, weight, output_name, style_triple_li raise ValueError("No element with {DEFAULT_STYLE} output style name found.") style_vectors_a = np.load( - os.path.join(model_dir, model_name_a, "style_vectors.npy") + os.path.join(assets_root, model_name_a, "style_vectors.npy") ) # (style_num_a, 256) style_vectors_b = np.load( - os.path.join(model_dir, model_name_b, "style_vectors.npy") + os.path.join(assets_root, model_name_b, "style_vectors.npy") ) # (style_num_b, 256) with open( - os.path.join(model_dir, model_name_a, "config.json"), encoding="utf-8" + os.path.join(assets_root, model_name_a, "config.json"), encoding="utf-8" ) as f: config_a = json.load(f) with open( - os.path.join(model_dir, model_name_b, "config.json"), encoding="utf-8" + os.path.join(assets_root, model_name_b, "config.json"), encoding="utf-8" ) as f: config_b = json.load(f) style2id_a = config_a["data"]["style2id"] @@ -73,7 +73,7 @@ def merge_style(model_name_a, model_name_b, weight, output_name, style_triple_li new_style2id[style_out] = len(new_style_vecs) - 1 new_style_vecs = np.array(new_style_vecs) - output_style_path = os.path.join(model_dir, output_name, "style_vectors.npy") + output_style_path = os.path.join(assets_root, output_name, "style_vectors.npy") np.save(output_style_path, new_style_vecs) new_config = config_a.copy() @@ -81,9 +81,9 @@ def merge_style(model_name_a, model_name_b, weight, output_name, style_triple_li new_config["data"]["style2id"] = new_style2id new_config["model_name"] = output_name with open( - os.path.join(model_dir, output_name, "config.json"), "w", encoding="utf-8" + os.path.join(assets_root, output_name, "config.json"), "w", encoding="utf-8" ) as f: - json.dump(new_config, f, indent=2) + json.dump(new_config, f, indent=2, ensure_ascii=False) return output_style_path, list(new_style2id.keys()) @@ -124,7 +124,7 @@ def merge_models( ) merged_model_path = os.path.join( - model_dir, output_name, f"{output_name}.safetensors" + assets_root, output_name, f"{output_name}.safetensors" ) os.makedirs(os.path.dirname(merged_model_path), exist_ok=True) save_file(merged_model_weight, merged_model_path) @@ -184,9 +184,9 @@ def merge_style_gr( def simple_tts(model_name, text, style=DEFAULT_STYLE, emotion_weight=1.0): - model_path = os.path.join(model_dir, model_name, f"{model_name}.safetensors") - config_path = os.path.join(model_dir, model_name, "config.json") - style_vec_path = os.path.join(model_dir, model_name, "style_vectors.npy") + model_path = os.path.join(assets_root, model_name, f"{model_name}.safetensors") + config_path = os.path.join(assets_root, model_name, "config.json") + style_vec_path = os.path.join(assets_root, model_name, "style_vectors.npy") model = Model(model_path, config_path, style_vec_path, device) return model.infer(text, style=style, style_weight=emotion_weight) @@ -198,12 +198,12 @@ def update_two_model_names_dropdown(): def load_styles_gr(model_name_a, model_name_b): - config_path_a = os.path.join(model_dir, model_name_a, "config.json") + config_path_a = os.path.join(assets_root, model_name_a, "config.json") with open(config_path_a, encoding="utf-8") as f: config_a = json.load(f) styles_a = list(config_a["data"]["style2id"].keys()) - config_path_b = os.path.join(model_dir, model_name_b, "config.json") + config_path_b = os.path.join(assets_root, model_name_b, "config.json") with open(config_path_b, encoding="utf-8") as f: config_b = json.load(f) styles_b = list(config_b["data"]["style2id"].keys()) @@ -249,7 +249,7 @@ Happy, Surprise, HappySurprise model_names = model_holder.model_names if len(model_names) == 0: - logger.error(f"モデルが見つかりませんでした。{model_dir}にモデルを置いてください。") + logger.error(f"モデルが見つかりませんでした。{assets_root}にモデルを置いてください。") sys.exit(1) initial_id = 0 initial_model_files = model_holder.model_files_dict[model_names[initial_id]] diff --git a/webui_style_vectors.py b/webui_style_vectors.py index 67aa886..d238eec 100644 --- a/webui_style_vectors.py +++ b/webui_style_vectors.py @@ -137,7 +137,7 @@ def save_style_vectors(model_name, style_names: str): style_dict = {name: i for i, name in enumerate(style_name_list)} json_dict["data"]["style2id"] = style_dict with open(config_path, "w", encoding="utf-8") as f: - json.dump(json_dict, f, indent=2) + json.dump(json_dict, f, indent=2, ensure_ascii=False) return f"成功!\n{style_vector_path}に保存し{config_path}を更新しました。" @@ -185,7 +185,7 @@ def save_style_vectors_from_files(model_name, audio_files_text, style_names_text json_dict["data"]["style2id"] = style_dict with open(config_path, "w", encoding="utf-8") as f: - json.dump(json_dict, f, indent=2) + json.dump(json_dict, f, indent=2, ensure_ascii=False) return f"成功!\n{style_vector_path}に保存し{config_path}を更新しました。" diff --git a/webui_train.py b/webui_train.py index a687cba..1c3a93d 100644 --- a/webui_train.py +++ b/webui_train.py @@ -57,7 +57,7 @@ def initialize(model_name, batch_size, epochs, save_every_steps, bf16_run): return False, "Step 1, Error: pretrainedフォルダが見つかりません。" with open(config_path, "w", encoding="utf-8") as f: - json.dump(config, f, indent=2) + json.dump(config, f, indent=2, ensure_ascii=False) if not os.path.exists("config.yml"): shutil.copy(src="default_config.yml", dst="config.yml") # yml_data = safe_load(open("config.yml", "r", encoding="utf-8"))