|
import os |
|
import shutil |
|
from os import listdir |
|
import gradio as gr |
|
from colorama import Fore |
|
|
|
def run_inference(model_name, pitch, input_path, f0_method, save_as, index_rate, volume_normalization, consonant_protection): |
|
|
|
model_filename = model_name + '.pth' |
|
index_temp = 'Index_Temp' |
|
|
|
|
|
if not os.path.exists(index_temp): |
|
os.mkdir(index_temp) |
|
print("Index_Temp folder created.") |
|
else: |
|
print("Index_Temp folder found.") |
|
|
|
|
|
index_file_path = os.path.join('logs/', model_name, '') |
|
for file_name in listdir(index_file_path): |
|
if file_name.startswith('added') and file_name.endswith('.index'): |
|
shutil.copy(index_file_path + file_name, os.path.join(index_temp, file_name)) |
|
print('Index file copied successfully.') |
|
|
|
|
|
indexfile_directory = os.getcwd() + '/' + index_temp |
|
files = os.listdir(indexfile_directory) |
|
index_filename = files[0] if files else None |
|
if index_filename is None: |
|
raise ValueError("Index file not found.") |
|
|
|
shutil.rmtree(index_temp) |
|
|
|
model_path = "assets/weights/" + model_filename |
|
index_path = os.path.join('logs', model_name, index_filename) |
|
|
|
if not os.path.exists(input_path): |
|
raise ValueError(f"{input_path} was not found.") |
|
|
|
os.environ['index_root'] = os.path.dirname(index_path) |
|
index_path = os.path.basename(index_path) |
|
|
|
os.environ['weight_root'] = os.path.dirname(model_path) |
|
|
|
|
|
cmd = f"python tools/cmd/infer_cli.py --f0up_key {pitch} --input_path {input_path} --index_path {index_path} --f0method {f0_method} --opt_path {save_as} --model_name {os.path.basename(model_path)} --index_rate {index_rate} --device 'cuda:0' --is_half True --filter_radius 3 --resample_sr 0 --rms_mix_rate {volume_normalization} --protect {consonant_protection}" |
|
os.system(f"rm -f {save_as}") |
|
os.system(cmd) |
|
|
|
return f"Inference completed, output saved at {save_as}.", save_as |
|
|
|
|
|
|
|
with gr.Blocks() as demo: |
|
with gr.Row(): |
|
gr.Markdown("# RVC V2 - EASY GUI") |
|
with gr.Row(): |
|
model_name = gr.Textbox(label="Model Name For Inference") |
|
with gr.Row(): |
|
input_path = gr.Audio(label="Input Audio Path", type="filepath") |
|
pitch = gr.Slider(minimum=-12, maximum=12, step=1, label="Pitch", value=0) |
|
f0_method = gr.Dropdown(choices=["rmvpe", "pm", "harvest"], label="f0 Method", value="rmvpe") |
|
index_rate = gr.Slider(minimum=0, maximum=1, step=0.01, label="Index Rate", value=0.5) |
|
volume_normalization = gr.Slider(minimum=0, maximum=1, step=0.01, label="Volume Normalization", value=0) |
|
consonant_protection = gr.Slider(minimum=0, maximum=1, step=0.01, label="Consonant Protection", value=0.5) |
|
save_as = gr.Textbox(value="/content/RVC/audios/output_audio.wav", label="Output Audio Path") |
|
|
|
run_btn = gr.Button("Run Inference") |
|
with gr.Row(): |
|
output_message = gr.Textbox(label="Output Message") |
|
output_audio = gr.Audio(label="Output Audio",interactive=False) |
|
|
|
|
|
|
|
demo.launch() |
|
|