From 5c0ad21d6b45d0f4cac00422834dd72656d9608b Mon Sep 17 00:00:00 2001 From: Neo Date: Wed, 18 Dec 2024 17:22:01 +0700 Subject: [PATCH] Add files via upload --- rvc_inferpy/__init__.py | 2 +- rvc_inferpy/cli.py | 19 ++++++++++-- rvc_inferpy/infer.py | 64 +++++++++++++++++++++++++++-------------- rvc_inferpy/modules.py | 15 ++-------- rvc_inferpy/pipeline.py | 23 +++++---------- 5 files changed, 69 insertions(+), 54 deletions(-) diff --git a/rvc_inferpy/__init__.py b/rvc_inferpy/__init__.py index 7c795a9..0817843 100644 --- a/rvc_inferpy/__init__.py +++ b/rvc_inferpy/__init__.py @@ -1 +1 @@ -from .infer import infer_audio, dl_model, download_rvc_model +from .infer import infer_audio, dl_model diff --git a/rvc_inferpy/cli.py b/rvc_inferpy/cli.py index 082a299..73d8048 100644 --- a/rvc_inferpy/cli.py +++ b/rvc_inferpy/cli.py @@ -14,7 +14,7 @@ def infer_audio_cli(): - parser = argparse.ArgumentParser(description="RVC CLI.") + parser = argparse.ArgumentParser(description="RVC INFERPY CLI VER.") parser.add_argument("--model_name", type=str, help="Name of the model.") parser.add_argument("--audio_path", type=str, help="Path to the input audio file.") parser.add_argument( @@ -71,9 +71,22 @@ def infer_audio_cli(): parser.add_argument( "--resample_sr", type=int, default=0, help="Resample sample rate." ) - + parser.add_argument( + "--hubert_model_path", + type=str, + default="hubert_base.pt", + help="Path to Hubert model.", + ) + parser.add_argument( + "--rmvpe_model_path", type=str, default="rmvpe.pt", help="Path to RMVPE model." + ) + parser.add_argument( + "--fcpe_model_path", type=str, default="fcpe.pt", help="Path to FCPE model." + ) args = parser.parse_args() + os.environ["rmvpe_model_path"] = args.rmvpe_model_path + os.environ["fcpe_model_path"] = args.fcpe_model_path configs = Configs("cuda:0", True) vc = VC(configs) pth_path, index_path = get_model(args.model_name) @@ -113,6 +126,7 @@ def infer_audio_cli(): args.min_pitch, args.max_pitch, args.f0_autotune, + args.hubert_model_path, ) if inference_info[0] == "Success.": print("Inference ran successfully.") @@ -148,6 +162,7 @@ def infer_audio_cli(): args.min_pitch, args.max_pitch, args.f0_autotune, + args.hubert_model_path, ) if inference_info[0] == "Success.": print("Inference ran successfully.") diff --git a/rvc_inferpy/infer.py b/rvc_inferpy/infer.py index 2a11e28..ea9356d 100644 --- a/rvc_inferpy/infer.py +++ b/rvc_inferpy/infer.py @@ -9,26 +9,8 @@ adjust_audio_lengths, combine_silence_nonsilent, ) -from rvc_inferpy.config_loader import * -import torch from pathlib import Path import requests -import os -import zipfile -import shutil -import urllib.request -import gdown - -models_dir = "models" - - -validate_config_and_files() - -BaseLoader(hubert_path=hubert_model_path, rmvpe_path=rmvpe_model_path) -rvcbasdl = lambda: print( - "RVC-based loader initialized." -) # Replace with the actual function -rvcbasdl() class Configs: @@ -95,6 +77,43 @@ def get_model(voice_model): ) +BASE_DIR = Path(os.getcwd()) +sys.path.append(str(BASE_DIR)) + +files_to_check = ["hubert_base.pt", "rmvpe.pt", "fcpe.pt"] + +missing_files = [file for file in files_to_check if not (BASE_DIR / file).exists()] + + +def dl_model(link, model_name, dir_name): + url = f"{link}/{model_name}" + response = requests.get(url, stream=True) + response.raise_for_status() + + target_path = dir_name / model_name + target_path.parent.mkdir( + parents=True, exist_ok=True + ) # Create the directory if it doesn't exist + + with open(target_path, "wb") as f: + for chunk in response.iter_content(chunk_size=8192): + f.write(chunk) + + print(f"{model_name} downloaded successfully!") + + +if missing_files: + RVC_DOWNLOAD_LINK = "https://huggingface.co/theNeofr/rvc-base/resolve/main" # Replace with the actual download link + + for model in missing_files: + print(f"Downloading {model}...") + dl_model(RVC_DOWNLOAD_LINK, model, BASE_DIR) + + print("All missing models have been downloaded!") +else: + pass + + def infer_audio( model_name, audio_path, @@ -118,11 +137,12 @@ def infer_audio( f0_autotune=False, audio_format="wav", resample_sr=0, - hubert_model_path=hubert_model_path, - rmvpe_model_path=rmvpe_model_path, - fcpe_model_path=fcpe_model_path, + hubert_model_path="hubert_base.pt", + rmvpe_model_path="rmvpe.pt", + fcpe_model_path="fcpe.pt", ): - + os.environ["rmvpe_model_path"] = rmvpe_model_path + os.environ["fcpe_model_path"] = fcpe_model_path configs = Configs("cuda:0", True) vc = VC(configs) pth_path, index_path = get_model(model_name) diff --git a/rvc_inferpy/modules.py b/rvc_inferpy/modules.py index 6a40e5b..112d917 100644 --- a/rvc_inferpy/modules.py +++ b/rvc_inferpy/modules.py @@ -22,17 +22,6 @@ import glob from shutil import move from fairseq import checkpoint_utils -from rvc_inferpy.config_loader import * - - -validate_config_and_files() - -BaseLoader(hubert_path=hubert_model_path, rmvpe_path=rmvpe_model_path) -rvcbasdl = lambda: print( - "RVC-based loader initialized." -) # Replace with the actual function -rvcbasdl() - sup_audioext = { "wav", @@ -239,7 +228,7 @@ def vc_single_dont_save( f0_min, f0_max, f0_autotune, - hubert_model_path=hubert_model_path, + hubert_model_path="hubert_base.pt", ): """ Performs inference without saving @@ -408,7 +397,7 @@ def vc_single( f0_min, f0_max, f0_autotune, - hubert_model_path=hubert_model_path, + hubert_model_path="hubert_base.pt", ): """ Performs inference with saving diff --git a/rvc_inferpy/pipeline.py b/rvc_inferpy/pipeline.py index 6ace100..e1d4fd3 100644 --- a/rvc_inferpy/pipeline.py +++ b/rvc_inferpy/pipeline.py @@ -33,15 +33,6 @@ import torch from rvc_inferpy.infer_list.rmvpe import RMVPE from rvc_inferpy.infer_list.fcpe import FCPE -from rvc_inferpy.config_loader import * - -validate_config_and_files() - -BaseLoader(hubert_path=hubert_model_path, rmvpe_path=rmvpe_model_path) -rvcbasdl = lambda: print( - "RVC-based loader initialized." -) # Replace with the actual function -rvcbasdl() @lru_cache @@ -265,11 +256,11 @@ def get_f0_pyin_computation(self, x, f0_min, f0_max): def get_rmvpe(self, x, *args, **kwargs): if not hasattr(self, "model_rmvpe"): - from rvc_inferpy.infer_list.rmvpe import RMVPE + from lib.infer.infer_libs.rmvpe import RMVPE logger.info(f"Loading rmvpe model, {os.environ['rmvpe_model_path']}") self.model_rmvpe = RMVPE( - rmvpe_model_path, + os.environ["rmvpe_model_path"], is_half=self.is_half, device=self.device, ) @@ -284,11 +275,11 @@ def get_rmvpe(self, x, *args, **kwargs): def get_pitch_dependant_rmvpe(self, x, f0_min=1, f0_max=40000, *args, **kwargs): if not hasattr(self, "model_rmvpe"): - from rvc_inferpy.infer_list.rmvpe import RMVPE + from lib.infer.infer_libs.rmvpe import RMVPE logger.info(f"Loading rmvpe model, {os.environ['rmvpe_model_path']}") self.model_rmvpe = RMVPE( - rmvpe_model_path, + os.environ["rmvpe_model_path"], is_half=self.is_half, device=self.device, ) @@ -304,7 +295,7 @@ def get_pitch_dependant_rmvpe(self, x, f0_min=1, f0_max=40000, *args, **kwargs): def get_fcpe(self, x, f0_min, f0_max, p_len, *args, **kwargs): self.model_fcpe = FCPE( - fcpe_model_path, + os.environ["fcpe_model_path"], f0_min=f0_min, f0_max=f0_max, dtype=torch.float32, @@ -534,11 +525,11 @@ def get_f0( ) elif f0_method == "rmvpe": if not hasattr(self, "model_rmvpe"): - from rvc_inferpy.infer_list.rmvpe import RMVPE + from lib.infer.infer_libs.rmvpe import RMVPE logger.info(f"Loading rmvpe model, {os.environ['rmvpe_model_path']}") self.model_rmvpe = RMVPE( - rmvpe_model_path, + os.environ["rmvpe_model_path"], is_half=self.is_half, device=self.device, )