From 26c81a14cb1d8a928b6dd9c79a537d6cf27af781 Mon Sep 17 00:00:00 2001 From: litongjava Date: Mon, 20 May 2024 18:58:21 -1000 Subject: [PATCH] 1.add trained path to scan model path --- .gitignore | 5 +++- GPT_SoVITS/inference_webui.py | 46 ++++++++++++++++++++++++++++------ GPT_SoVITS/pyutils/__init__.py | 0 GPT_SoVITS/pyutils/logs.py | 24 ++++++++++++++++++ GPT_SoVITS/utils.py | 11 +++----- docs/cn/inference_cpu.md | 1 + trained/.gitignore | 3 +++ 7 files changed, 74 insertions(+), 16 deletions(-) create mode 100644 GPT_SoVITS/pyutils/__init__.py create mode 100644 GPT_SoVITS/pyutils/logs.py create mode 100644 docs/cn/inference_cpu.md create mode 100644 trained/.gitignore diff --git a/.gitignore b/.gitignore index c484cf22..c938d376 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,7 @@ logs reference GPT_weights SoVITS_weights -TEMP \ No newline at end of file +TEMP +app.log +gweight.txt +sweight.txt \ No newline at end of file diff --git a/GPT_SoVITS/inference_webui.py b/GPT_SoVITS/inference_webui.py index 4fe8045d..bca4a43e 100644 --- a/GPT_SoVITS/inference_webui.py +++ b/GPT_SoVITS/inference_webui.py @@ -8,6 +8,8 @@ ''' import os, re, logging import LangSegment +from pyutils.logs import llog + logging.getLogger("markdown_it").setLevel(logging.ERROR) logging.getLogger("urllib3").setLevel(logging.ERROR) logging.getLogger("httpcore").setLevel(logging.ERROR) @@ -530,19 +532,47 @@ def change_choices(): pretrained_sovits_name = "GPT_SoVITS/pretrained_models/s2G488k.pth" pretrained_gpt_name = "GPT_SoVITS/pretrained_models/s1bert25hz-2kh-longer-epoch=68e-step=50232.ckpt" -SoVITS_weight_root = "SoVITS_weights" -GPT_weight_root = "GPT_weights" -os.makedirs(SoVITS_weight_root, exist_ok=True) -os.makedirs(GPT_weight_root, exist_ok=True) +SoVITS_weight_root = ["SoVITS_weights","trained"] +GPT_weight_root = ["GPT_weights","trained"] + +for path in SoVITS_weight_root: + os.makedirs(path, exist_ok=True) + +for path in GPT_weight_root: + os.makedirs(path, exist_ok=True) def get_weights_names(): SoVITS_names = [pretrained_sovits_name] - for name in os.listdir(SoVITS_weight_root): - if name.endswith(".pth"): SoVITS_names.append("%s/%s" % (SoVITS_weight_root, name)) + for path in SoVITS_weight_root: + llog.info(f"scan model path:{path}") + for name in os.listdir(path): + llog.info(f"scan sub model path:{name}") + #if os.path.isdir(name): no working + if os.path.isfile(name): + if name.endswith(".pth"): SoVITS_names.append("%s/%s" % (path, name)) + else: + subPath = os.path.join(path, name) + for modelName in os.listdir(subPath): + if modelName.endswith(".pth"): + modelPath = os.path.join(subPath,modelName) + llog.info(f"add model path:{modelPath}") + SoVITS_names.append(modelPath) + + GPT_names = [pretrained_gpt_name] - for name in os.listdir(GPT_weight_root): - if name.endswith(".ckpt"): GPT_names.append("%s/%s" % (GPT_weight_root, name)) + for path in GPT_weight_root: + for name in os.listdir(path): + if os.path.isfile(name): + if name.endswith(".ckpt"): GPT_names.append("%s/%s" % (path, name)) + else: + subPath = os.path.join(path, name) + for modelName in os.listdir(subPath): + if modelName.endswith(".pth"): + modelPath = os.path.join(subPath, modelName) + llog.info(f"add model path:{modelPath}") + GPT_names.append(modelPath) + return SoVITS_names, GPT_names diff --git a/GPT_SoVITS/pyutils/__init__.py b/GPT_SoVITS/pyutils/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/GPT_SoVITS/pyutils/logs.py b/GPT_SoVITS/pyutils/logs.py new file mode 100644 index 00000000..1fe2ffcd --- /dev/null +++ b/GPT_SoVITS/pyutils/logs.py @@ -0,0 +1,24 @@ +import logging +from logging.handlers import RotatingFileHandler + +# 设置日志记录器 +llog = logging.getLogger(__name__) +llog.setLevel(logging.INFO) +llog.propagate = False # 防止日志事件传递给根记录器 + +# 创建控制台日志处理器 +console_handler = logging.StreamHandler() +console_handler.setLevel(logging.INFO) + +# 创建文件日志处理器 +file_handler = RotatingFileHandler('app.log', maxBytes=1024 * 1024 * 10, backupCount=5) +file_handler.setLevel(logging.INFO) + +# 设置日志格式,包括文件名和行号 +formatter = logging.Formatter('%(asctime)s - %(filename)s:%(lineno)d - %(levelname)s - %(message)s') +console_handler.setFormatter(formatter) +file_handler.setFormatter(formatter) + +# 将处理器添加到日志记录器 +llog.addHandler(console_handler) +#llog.addHandler(file_handler) \ No newline at end of file diff --git a/GPT_SoVITS/utils.py b/GPT_SoVITS/utils.py index 7984b5a8..99cd5066 100644 --- a/GPT_SoVITS/utils.py +++ b/GPT_SoVITS/utils.py @@ -1,17 +1,14 @@ -import os -import glob -import sys import argparse -import logging +import glob import json +import logging +import os import subprocess +import sys import traceback import librosa -import numpy as np -from scipy.io.wavfile import read import torch -import logging logging.getLogger("numba").setLevel(logging.ERROR) logging.getLogger("matplotlib").setLevel(logging.ERROR) diff --git a/docs/cn/inference_cpu.md b/docs/cn/inference_cpu.md new file mode 100644 index 00000000..f3a6aa13 --- /dev/null +++ b/docs/cn/inference_cpu.md @@ -0,0 +1 @@ +# 使用cpu推理 diff --git a/trained/.gitignore b/trained/.gitignore new file mode 100644 index 00000000..aa4e5510 --- /dev/null +++ b/trained/.gitignore @@ -0,0 +1,3 @@ +* +!.gitignore +!character_info.json \ No newline at end of file