From ac9a34a03f19d215c7a3240bddf383034ec6cbb7 Mon Sep 17 00:00:00 2001 From: Sayo Date: Tue, 6 May 2025 20:24:16 +0800 Subject: [PATCH] [fix] encoding --- data_sampler.py | 5 +---- models/lyrics_utils/zh_num2words.py | 2 +- pipeline_ace_step.py | 2 +- trainer.py | 4 ++-- 4 files changed, 5 insertions(+), 8 deletions(-) diff --git a/data_sampler.py b/data_sampler.py index 306fc79..64b1636 100644 --- a/data_sampler.py +++ b/data_sampler.py @@ -6,16 +6,13 @@ import random DEFAULT_ROOT_DIR = "examples/input_params" - class DataSampler: def __init__(self, root_dir=DEFAULT_ROOT_DIR): self.root_dir = root_dir - - # glob self.input_params_files = list(Path(self.root_dir).glob("*.json")) def load_json(self, file_path): - with open(file_path, "r") as f: + with open(file_path, "r", encoding="utf-8") as f: return json.load(f) def sample(self): diff --git a/models/lyrics_utils/zh_num2words.py b/models/lyrics_utils/zh_num2words.py index 2c6a941..8029b15 100644 --- a/models/lyrics_utils/zh_num2words.py +++ b/models/lyrics_utils/zh_num2words.py @@ -1166,7 +1166,7 @@ if __name__ == "__main__": ) ndone = 0 - with open(args.ifile, "r", encoding="utf8") as istream, open(args.ofile, "w+", encoding="utf8") as ostream: + with open(args.ifile, "r", encoding="utf-8") as istream, open(args.ofile, "w+", encoding="utf-8") as ostream: if args.format == "tsv": reader = csv.DictReader(istream, delimiter="\t") assert "TEXT" in reader.fieldnames diff --git a/pipeline_ace_step.py b/pipeline_ace_step.py index 9f3b671..3efe548 100644 --- a/pipeline_ace_step.py +++ b/pipeline_ace_step.py @@ -1172,7 +1172,7 @@ class ACEStepPipeline: for output_audio_path in output_paths: input_params_json_save_path = output_audio_path.replace(f".{format}", "_input_params.json") input_params_json["audio_path"] = output_audio_path - with open(input_params_json_save_path, "w") as f: + with open(input_params_json_save_path, "w", encoding="utf-8") as f: json.dump(input_params_json, f, indent=4, ensure_ascii=False) return output_paths + [input_params_json] diff --git a/trainer.py b/trainer.py index 6defa7c..2289e77 100644 --- a/trainer.py +++ b/trainer.py @@ -74,7 +74,7 @@ class Pipeline(LightningModule): from peft import LoraConfig except ImportError: raise ImportError("Please install peft library to use LoRA training") - with open(lora_config_path) as f: + with open(lora_config_path, encoding="utf-8") as f: lora_config = json.load(f) lora_config = LoraConfig(**lora_config) transformers.add_adapter(adapter_config=lora_config) @@ -626,7 +626,7 @@ class Pipeline(LightningModule): os.makedirs(save_dir, exist_ok=True) torchaudio.save(f"{save_dir}/target_wav_{key}_{i}.flac", target_wav.float().cpu(), sr) torchaudio.save(f"{save_dir}/pred_wav_{key}_{i}.flac", pred_wav.float().cpu(), sr) - with open(f"{save_dir}/key_prompt_lyric_{key}_{i}.txt", "w") as f: + with open(f"{save_dir}/key_prompt_lyric_{key}_{i}.txt", "w", encoding="utf-8") as f: f.write(key_prompt_lyric) i += 1