Spaces:
Running
Running
zhzluke96 commited on
Commit ·
9d9fe0d
1
Parent(s): ba0472f
update
Browse filesFiles changed (6)
8 unmodified lines9101112131415168 unmodified lines# Model inference optionsHALF=TrueOFF_TQDM=TrueDEBUG_GENERATE=True# Text-to-Speech (TTS) configurationTTS_MAX_LEN=10008 unmodified lines910111213141516178 unmodified lines# Model inference optionsHALF=TrueOFF_TQDM=DEBUG_GENERATE=TruePRELOAD_MODELS=True# Text-to-Speech (TTS) configurationTTS_MAX_LEN=1000
111 unmodified lines1121131141151161171 unmodified line1191201211221231241251 unmodified line1271281291301311321331 unmodified line1351361371381391401414 unmodified lines146147148149150151152153154155156157158159160161162163164165166111 unmodified linesdtype_gpt = dtype_gpt or dtypedtype_decoder = dtype_decoder or dtypeif vocos_config_path:vocos = (Vocos.from_hparams(vocos_config_path)1 unmodified line.eval())assert vocos_ckpt_path, "vocos_ckpt_path should not be None"vocos.load_state_dict(torch.load(vocos_ckpt_path))self.pretrain_models["vocos"] = vocosself.logger.log(logging.INFO, "vocos loaded.")1 unmodified linecfg = OmegaConf.load(dvae_config_path)dvae = DVAE(**cfg).to(device=device, dtype=dtype_dvae).eval()assert dvae_ckpt_path, "dvae_ckpt_path should not be None"dvae.load_state_dict(torch.load(dvae_ckpt_path, map_location=device))self.pretrain_models["dvae"] = dvaeself.logger.log(logging.INFO, "dvae loaded.")1 unmodified linecfg = OmegaConf.load(gpt_config_path)gpt = GPT_warpper(**cfg).to(device=device, dtype=dtype_gpt).eval()assert gpt_ckpt_path, "gpt_ckpt_path should not be None"gpt.load_state_dict(torch.load(gpt_ckpt_path, map_location=device))if compile and "cuda" in str(device):self.logger.info("compile gpt model")gpt.gpt.forward = torch.compile(4 unmodified linesassert os.path.exists(spk_stat_path), f"Missing spk_stat.pt: {spk_stat_path}"self.pretrain_models["spk_stat"] = torch.load(spk_stat_path).to(device=device, dtype=dtype)self.logger.log(logging.INFO, "gpt loaded.")if decoder_config_path:cfg = OmegaConf.load(decoder_config_path)decoder = DVAE(**cfg).to(device=device, dtype=dtype_decoder).eval()assert decoder_ckpt_path, "decoder_ckpt_path should not be None"decoder.load_state_dict(torch.load(decoder_ckpt_path, map_location=device))self.pretrain_models["decoder"] = decoderself.logger.log(logging.INFO, "decoder loaded.")if tokenizer_path:tokenizer = torch.load(tokenizer_path, map_location=device)tokenizer.padding_side = "left"self.pretrain_models["tokenizer"] = tokenizerself.logger.log(logging.INFO, "tokenizer loaded.")111 unmodified lines1121131141151161171181191 unmodified line1211221231241251261271281291 unmodified line1311321331341351361371 unmodified line1391401411421431441454 unmodified lines150151152153154155156157158159160161162163164165166167168169170171172111 unmodified linesdtype_gpt = dtype_gpt or dtypedtype_decoder = dtype_decoder or dtypemap_location = torch.device("cpu")if vocos_config_path:vocos = (Vocos.from_hparams(vocos_config_path)1 unmodified line.eval())assert vocos_ckpt_path, "vocos_ckpt_path should not be None"vocos.load_state_dict(torch.load(vocos_ckpt_path, map_location=map_location))self.pretrain_models["vocos"] = vocosself.logger.log(logging.INFO, "vocos loaded.")1 unmodified linecfg = OmegaConf.load(dvae_config_path)dvae = DVAE(**cfg).to(device=device, dtype=dtype_dvae).eval()assert dvae_ckpt_path, "dvae_ckpt_path should not be None"dvae.load_state_dict(torch.load(dvae_ckpt_path, map_location=map_location))self.pretrain_models["dvae"] = dvaeself.logger.log(logging.INFO, "dvae loaded.")1 unmodified linecfg = OmegaConf.load(gpt_config_path)gpt = GPT_warpper(**cfg).to(device=device, dtype=dtype_gpt).eval()assert gpt_ckpt_path, "gpt_ckpt_path should not be None"gpt.load_state_dict(torch.load(gpt_ckpt_path, map_location=map_location))if compile and "cuda" in str(device):self.logger.info("compile gpt model")gpt.gpt.forward = torch.compile(4 unmodified linesassert os.path.exists(spk_stat_path), f"Missing spk_stat.pt: {spk_stat_path}"self.pretrain_models["spk_stat"] = torch.load(spk_stat_path, map_location=map_location).to(device=device, dtype=dtype)self.logger.log(logging.INFO, "gpt loaded.")if decoder_config_path:cfg = OmegaConf.load(decoder_config_path)decoder = DVAE(**cfg).to(device=device, dtype=dtype_decoder).eval()assert decoder_ckpt_path, "decoder_ckpt_path should not be None"decoder.load_state_dict(torch.load(decoder_ckpt_path, map_location=map_location))self.pretrain_models["decoder"] = decoderself.logger.log(logging.INFO, "decoder loaded.")if tokenizer_path:tokenizer = torch.load(tokenizer_path, map_location=map_location)tokenizer.padding_side = "left"self.pretrain_models["tokenizer"] = tokenizerself.logger.log(logging.INFO, "tokenizer loaded.")
1234567 unmodified lines1415161718192013 unmodified lines343536373839404142434445import gcimport osfrom typing import List, Literalimport numpy as npfrom modules.devices import devices7 unmodified linesfrom pathlib import Pathfrom threading import Lockfrom modules import configimport logging13 unmodified linesdef load_model(self):hparams = HParams.load(Path(MODELS_DIR) / "resemble-enhance")enhancer = Enhancer(hparams).to(device=self.device, dtype=self.dtype).eval()state_dict = torch.load(Path(MODELS_DIR) / "resemble-enhance" / "mp_rank_00_model_states.pt",map_location=self.device,)["module"]enhancer.load_state_dict(state_dict)self.hparams = hparamsself.enhancer = enhancer123457 unmodified lines13141516171813 unmodified lines32333435363738394041424344import gcfrom typing import Literalimport numpy as npfrom modules.devices import devices7 unmodified linesfrom pathlib import Pathfrom threading import Lockimport logging13 unmodified linesdef load_model(self):hparams = HParams.load(Path(MODELS_DIR) / "resemble-enhance")enhancer = Enhancer(hparams)state_dict = torch.load(Path(MODELS_DIR) / "resemble-enhance" / "mp_rank_00_model_states.pt",map_location="cpu",)["module"]enhancer.load_state_dict(state_dict)enhancer.to(device=self.device, dtype=self.dtype).eval()self.hparams = hparamsself.enhancer = enhancer
12345678967 unmodified lines7778798081824 unmodified lines8788899091922 unmodified lines9596979899100import loggingfrom modules.devices import devicesimport argparseimport torchfrom modules import configfrom modules.utils import envfrom modules import generate_audiofrom modules.api.Api import APIManager67 unmodified linesaction="store_true",help="Enable debug mode for audio generation",)def process_model_args(args):4 unmodified linesno_half = env.get_and_update_env(args, "no_half", False, bool)off_tqdm = env.get_and_update_env(args, "off_tqdm", False, bool)debug_generate = env.get_and_update_env(args, "debug_generate", False, bool)generate_audio.setup_lru_cache()devices.reset_device()2 unmodified linesif debug_generate:generate_audio.logger.setLevel(logging.DEBUG)def setup_uvicon_args(parser: argparse.ArgumentParser):parser.add_argument("--host", type=str, help="Host to run the server on")1234567891067 unmodified lines78798081828384858687884 unmodified lines939495969798992 unmodified lines102103104105106107108109110111import loggingfrom modules.Enhancer.ResembleEnhance import load_enhancerfrom modules.devices import devicesimport argparsefrom modules import configfrom modules.models import load_chat_ttsfrom modules.utils import envfrom modules import generate_audiofrom modules.api.Api import APIManager67 unmodified linesaction="store_true",help="Enable debug mode for audio generation",)parser.add_argument("--preload_models",action="store_true",help="Preload all models at startup",)def process_model_args(args):4 unmodified linesno_half = env.get_and_update_env(args, "no_half", False, bool)off_tqdm = env.get_and_update_env(args, "off_tqdm", False, bool)debug_generate = env.get_and_update_env(args, "debug_generate", False, bool)preload_models = env.get_and_update_env(args, "preload_models", False, bool)generate_audio.setup_lru_cache()devices.reset_device()2 unmodified linesif debug_generate:generate_audio.logger.setLevel(logging.DEBUG)if preload_models:load_chat_tts()load_enhancer()def setup_uvicon_args(parser: argparse.ArgumentParser):parser.add_argument("--host", type=str, help="Host to run the server on")
65 unmodified lines66676869707172737465 unmodified linesdisplay: none !important;}.progress-bar{height: 30px !important;}.progress-bar span {text-align: right;65 unmodified lines66676869707172737465 unmodified linesdisplay: none !important;}/* .progress-bar{height: 30px !important;} */.progress-bar span {text-align: right;
12345678910111213149 unmodified lines2425262728293066 unmodified lines97989910010110254 unmodified lines15715815916016116256 unmodified lines219220221222223224225import iofrom typing import Unionimport numpy as npfrom modules.Enhancer.ResembleEnhance import apply_audio_enhance as _apply_audio_enhancefrom modules.devices import devicesfrom modules.synthesize_audio import synthesize_audiofrom modules.utils.hf import spacesfrom modules.webui import webui_configimport torchfrom modules.ssml_parser.SSMLParser import create_ssml_parser, SSMLBreak, SSMLSegmentfrom modules.SynthesizeSegments import SynthesizeSegments, combine_audio_segments9 unmodified linesfrom modules.utils import audiofrom modules.SentenceSplitter import SentenceSplitterfrom pydub import AudioSegmentimport torch.profiler66 unmodified linesenable_denoise=False,eos: str = "[uv_break]",spliter_thr: int = 100,):try:batch_size = int(batch_size)54 unmodified linesspk_file=None,spliter_thr: int = 100,eos: str = "[uv_break]",):try:batch_size = int(batch_size)56 unmodified lines@torch.inference_mode()@spaces.GPU(duration=120)def refine_text(text: str, prompt: str):text = text_normalize(text)return refiner.refine_text(text, prompt=prompt)123456789101112139 unmodified lines23242526272866 unmodified lines959697989910010154 unmodified lines15615715815916016116256 unmodified lines219220221222223224225226227228229from typing import Unionimport numpy as npfrom modules.Enhancer.ResembleEnhance import apply_audio_enhance as _apply_audio_enhancefrom modules.synthesize_audio import synthesize_audiofrom modules.utils.hf import spacesfrom modules.webui import webui_configimport torchimport gradio as grfrom modules.ssml_parser.SSMLParser import create_ssml_parser, SSMLBreak, SSMLSegmentfrom modules.SynthesizeSegments import SynthesizeSegments, combine_audio_segments9 unmodified linesfrom modules.utils import audiofrom modules.SentenceSplitter import SentenceSplitterimport torch.profiler66 unmodified linesenable_denoise=False,eos: str = "[uv_break]",spliter_thr: int = 100,progress=gr.Progress(track_tqdm=True),):try:batch_size = int(batch_size)54 unmodified linesspk_file=None,spliter_thr: int = 100,eos: str = "[uv_break]",progress=gr.Progress(track_tqdm=True),):try:batch_size = int(batch_size)56 unmodified lines@torch.inference_mode()@spaces.GPU(duration=120)def refine_text(text: str,prompt: str,progress=gr.Progress(track_tqdm=True),):text = text_normalize(text)return refiner.refine_text(text, prompt=prompt)
.env.webui+2-1
modules/ChatTTS/ChatTTS/core.py+14-8
modules/Enhancer/ResembleEnhance.py+4-5
modules/api/api_setup.py+12-1
modules/webui/css/style.css+2-2
modules/webui/webui_utils.py+8-4