import gradio as gr from rvc_inferpy import infer_audio import os import zipfile import shutil import urllib.request import gdown import os import glob import yt_dlp from audio_separator.separator import Separator roformer_uvr = { 'BS-Roformer-Viperx-1297': 'model_bs_roformer_ep_317_sdr_12.9755.ckpt', 'BS-Roformer-Viperx-1296': 'model_bs_roformer_ep_368_sdr_12.9628.ckpt', 'BS-Roformer-Viperx-1053': 'model_bs_roformer_ep_937_sdr_10.5309.ckpt', 'Mel-Roformer-Viperx-1143': 'model_mel_band_roformer_ep_3005_sdr_11.4360.ckpt', 'BS-Roformer-De-Reverb': 'deverb_bs_roformer_8_384dim_10depth.ckpt', 'Mel-Roformer-Crowd-Aufr33-Viperx': 'mel_band_roformer_crowd_aufr33_viperx_sdr_8.7144.ckpt', 'Mel-Roformer-Denoise-Aufr33': 'denoise_mel_band_roformer_aufr33_sdr_27.9959.ckpt', 'Mel-Roformer-Denoise-Aufr33-Aggr' : 'denoise_mel_band_roformer_aufr33_aggr_sdr_27.9768.ckpt', 'Mel-Roformer-Karaoke-Aufr33-Viperx': 'mel_band_roformer_karaoke_aufr33_viperx_sdr_10.1956.ckpt', 'MelBand Roformer | Vocals by Kimberley Jensen' : 'vocals_mel_band_roformer.ckpt', 'MelBand Roformer Kim | FT by unwa' : 'mel_band_roformer_kim_ft_unwa.ckpt', 'MelBand Roformer Kim | Inst V1 by Unwa' : 'melband_roformer_inst_v1.ckpt', 'MelBand Roformer Kim | Inst V1 (E) by Unwa' : 'melband_roformer_inst_v1e.ckpt', 'MelBand Roformer Kim | Inst V2 by Unwa' : 'melband_roformer_inst_v2.ckpt', 'MelBand Roformer Kim | InstVoc Duality V1 by Unwa' : 'melband_roformer_instvoc_duality_v1.ckpt', 'MelBand Roformer Kim | InstVoc Duality V2 by Unwa' : 'melband_roformer_instvox_duality_v2.ckpt', 'MelBand Roformer | De-Reverb by anvuew' : 'dereverb_mel_band_roformer_anvuew_sdr_19.1729.ckpt', 'MelBand Roformer | De-Reverb Less Aggressive by anvuew' : 'dereverb_mel_band_roformer_less_aggressive_anvuew_sdr_18.8050.ckpt', 'MelBand Roformer | De-Reverb-Echo by Sucial' : 'dereverb-echo_mel_band_roformer_sdr_10.0169.ckpt', 'MelBand Roformer | De-Reverb-Echo V2 by Sucial' : 'dereverb-echo_mel_band_roformer_sdr_13.4843_v2.ckpt', 'MelBand Roformer Kim | SYHFT by SYH99999' : 'MelBandRoformerSYHFT.ckpt', 'MelBand Roformer Kim | SYHFT V2 by SYH99999' : 'MelBandRoformerSYHFTV2.ckpt', 'MelBand Roformer Kim | SYHFT V2.5 by SYH99999' : 'MelBandRoformerSYHFTV2.5.ckpt', 'MelBand Roformer Kim | SYHFT V3 by SYH99999' : 'MelBandRoformerSYHFTV3Epsilon.ckpt', 'MelBand Roformer Kim | Big SYHFT V1 by SYH99999' : 'MelBandRoformerBigSYHFTV1.ckpt', 'MelBand Roformer Kim | Big Beta 4 FT by unwa' : 'melband_roformer_big_beta4.ckpt', 'MelBand Roformer Kim | Big Beta 5e FT by unwa' : 'melband_roformer_big_beta5e.ckpt', 'BS Roformer | Chorus Male-Female by Sucial' : 'model_chorus_bs_roformer_ep_267_sdr_24.1275.ckpt', 'MelBand Roformer | Aspiration by Sucial' : 'aspiration_mel_band_roformer_sdr_18.9845.ckpt', 'MelBand Roformer | Aspiration Less Aggressive by Sucial' : 'aspiration_mel_band_roformer_less_aggr_sdr_18.1201.ckpt', 'MelBand Roformer | Bleed Suppressor V1 by unwa-97chris' : 'mel_band_roformer_bleed_suppressor_v1.ckpt' } main_dir = os.getcwd() models_dir = os.path.join(main_dir, "models") audios_dir = os.path.join(main_dir, "audios") os.makedirs(models_dir, exist_ok=True) separator = Separator(output_dir=audios_dir) audio_files=[] for filename in os.listdir(audios_dir): if filename.endswith(('.wav','.mp3','.ogg','.flac','.m4a','.aac','.mp4')): audio_files.append(os.path.join(audios_dir,filename).replace('\\', '/')) def downloader(url, cookies): ydl_opts = { 'format': 'bestaudio/best', 'postprocessors': [{ 'key': 'FFmpegExtractAudio', 'preferredcodec': 'wav', 'preferredquality': '192', }], 'outtmpl': os.path.join(audios_dir, '%(title)s.%(ext)s'), 'cookiefile': f'{cookies}', # Update this path } with yt_dlp.YoutubeDL(ydl_opts) as ydl: info = ydl.extract_info(url, download=True) video_title = info.get('title', 'audio') file_path = os.path.join(audios_dir, f"{video_title}.wav") return file_path def checker(url): return "http" in url def separater(input_audio,load_yu): # Define output filenames output_names = { "Vocals": "vocals_output", "Instrumental": "instrumental_output", } # Perform separation separator.load_model(model_filename=load_yu) output_files = separator.separate(input_audio, output_names) os.remove(output_files["Instrumental"]) return output_files["Vocals"] def extract_zip(extraction_folder, zip_name): os.makedirs(extraction_folder, exist_ok=True) with zipfile.ZipFile(zip_name, 'r') as zip_ref: zip_ref.extractall(extraction_folder) os.remove(zip_name) index_filepath, model_filepath = None, None for root, dirs, files in os.walk(extraction_folder): for name in files: if name.endswith('.index') and os.stat(os.path.join(root, name)).st_size > 1024 * 100: index_filepath = os.path.join(root, name) if name.endswith('.pth') and os.stat(os.path.join(root, name)).st_size > 1024 * 1024 * 40: model_filepath = os.path.join(root, name) if not model_filepath: raise Exception(f'No .pth model file was found in the extracted zip. Please check {extraction_folder}.') os.rename(model_filepath, os.path.join(extraction_folder, os.path.basename(model_filepath))) if index_filepath: os.rename(index_filepath, os.path.join(extraction_folder, os.path.basename(index_filepath))) for filepath in os.listdir(extraction_folder): if os.path.isdir(os.path.join(extraction_folder, filepath)): shutil.rmtree(os.path.join(extraction_folder, filepath)) def download_online_model(url, dir_name): try: print(f'[~] Downloading voice model with name {dir_name}...') zip_name = dir_name + ".zip" extraction_folder = os.path.join(models_dir, dir_name) if os.path.exists(extraction_folder): raise Exception(f'Voice model directory {dir_name} already exists! Choose a different name.') if 'drive.google.com' in url: gdown.download(url, output=zip_name, use_cookies=True, quiet=True, fuzzy=True) else: urllib.request.urlretrieve(url, zip_name) print('[~] Extracting zip file...') extract_zip(extraction_folder, zip_name) return f'[+] {dir_name} Model successfully downloaded!' except Exception as e: raise gr.Error(e) def process_audio(model_name, sound_path, f0_change, f0_method, output_format): try: print("NEO RVC-E FORK:") print(f"Models: {model_name},\n {sound_path},\n F0 Pitch: {f0_change}\n, F0 Method: {f0_method}.") inferred_audio = infer_audio( model_name=model_name, audio_path=sound_path, f0_change=f0_change, f0_method=f0_method ) return inferred_audio except Exception as e: print(e) raise gr.Error(e) def save_to_wav2(dropbox): file_path=dropbox shutil.move(file_path,audios_dir) return os.path.join(audios_dir,os.path.basename(file_path)) def get_name(): if len(audio_files) > 0: return sorted(audio_files)[0] else: return '' def change_choices2(): audio_files=[] for filename in os.listdir(audios_dir): if filename.endswith(('.wav','.mp3','.ogg','.flac','.m4a','.aac','.mp4')): audio_files.append(os.path.join(audios_dir,filename).replace('\\', '/')) return {"choices": sorted(audio_files), "__type__": "update"}, {"__type__": "update"} def get_model_files(): model_files=[] for root, dirs, files in os.walk(models_dir): for name in files: if filename.endswith(('.pth')): model_files.append(os.path.join(root, name).replace('\\', '/')) if len(model_files) == 0: model_files = [""] return model_files def update_model_name(): return gr.update(choices=get_model_files()) with gr.Blocks(theme=gr.themes.Base(), title=" rvc inferpy") as demo: gr.Markdown("

rvc inferpy (Neo RVC Fork)

") gr.Markdown("most simplest RVC inference") with gr.Tabs(): with gr.TabItem("Inference"): with gr.Row(): with gr.Row(): model_name_input = gr.Dropdown(label="Model Name", choices=get_model_files(), value=get_model_files()[0], allow_custom_value=True) refresh_models = gr.Button("Refresh Models") refresh_models.click(fn=update_model_name, inputs=None, outputs=model_name_input) input_audio0 = gr.Dropdown( label="Choose your audio.", value="", choices=audio_files ) with gr.Row(): with gr.TabItem("Upload"): with gr.Row(): dropbox = gr.Audio(label="Upload Audio for inference") with gr.TabItem("UVR"): with gr.Row(): roformer_model = gr.Dropdown( label = "Select the model", choices = list(roformer_uvr.keys()), value = lambda : None, interactive = True ) uvr_inputs = gr.Audio(label="UVR Input Audio") with gr.Accordion("using link"): gr.Markdown("see how to get your cookies in [yt dlp FAQ](https://github.com/yt-dlp/yt-dlp/wiki/FAQ)") yt_dlp_inous = gr.Textbox(label="yt_dlp url inputs") yt_dlp_cook = gr.File(label="yt_dlp url inputs") download_aud = gr.Button("Download") download_aud.click(fn=downloader, inputs=[yt_dlp_inous, yt_dlp_cook], outputs=uvr_inputs) separators = gr.Button("Separate") separators.click(fn=separater, inputs=[uvr_inputs, roformer_model], outputs=input_audio0) dropbox.upload(fn=save_to_wav2, inputs=[dropbox], outputs=[input_audio0])\ #.then(fn=change_choices2, inputs=None, outputs=[input_audio0])\ with gr.Accordion("Inference Settings"): with gr.Row(): f0_change_input = gr.Number(label="F0 Change", value=0) f0_method_input = gr.Dropdown(label="F0 Method", choices=["crepe", "dio", "harvest", "rmvpe", "fcpe", "hybrid[fcpe+rmvpe]"], value="crepe") with gr.Row(): with gr.Row(): submit_button = gr.Button("Run Inference") output_audio = gr.Audio(label="Inferred Audio", type="filepath") submit_button.click( fn=process_audio, inputs=[model_name_input, input_audio0, f0_change_input, f0_method_input], outputs=output_audio ) with gr.TabItem("Download Models"): with gr.Row(): url_input = gr.Textbox(label="Model URL") url_name_input = gr.Textbox(label="Model Name") with gr.Row(): download_button = gr.Button("Download") url_output = gr.Textbox(label="Output") download_button.click( fn=download_online_model, inputs=[url_input, url_name_input], outputs=url_output ) with gr.TabItem("Credits"): gr.Markdown( """ Credits to\n * IAHispano's Applio: Base of this project.\n * RVC-Project: Original RVC repository.\n * [John6666](https://huggingface.co/John6666), helping me to improve the code """ ) demo.launch(debug=True, share=True)