-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathapp.py
82 lines (63 loc) · 3.96 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import os
import gradio as gr
from download_audio import download_youtube_audio
def run_inference(
model_name, input_path, output_path, export_format, f0_method, f0_up_key,
filter_radius, rms_mix_rate, protect, index_rate, hop_length, clean_strength,
split_audio, clean_audio, f0_autotune, formant_shift, formant_qfrency,
formant_timbre, embedder_model, embedder_model_custom
):
current_dir = os.getcwd()
model_folder = os.path.join(current_dir, f"logs/{model_name}")
if not os.path.exists(model_folder):
return f"Model directory not found: {model_folder}"
files_in_folder = os.listdir(model_folder)
pth_path = next((f for f in files_in_folder if f.endswith(".pth")), None)
index_file = next((f for f in files_in_folder if f.endswith(".index")), None)
if pth_path is None or index_file is None:
return "No model found."
pth_file = os.path.join(model_folder, pth_path)
index_file = os.path.join(model_folder, index_file)
command = f"python rvc_cli.py infer --pitch '{f0_up_key}' --filter_radius '{filter_radius}' " \
f"--volume_envelope '{rms_mix_rate}' --index_rate '{index_rate}' --hop_length '{hop_length}' " \
f"--protect '{protect}' --f0_autotune '{f0_autotune}' --f0_method '{f0_method}' " \
f"--input_path '{input_path}' --output_path '{output_path}' --pth_path '{pth_file}' " \
f"--index_path '{index_file}' --split_audio '{split_audio}' --clean_audio '{clean_audio}' " \
f"--clean_strength '{clean_strength}' --export_format '{export_format}' " \
f"--embedder_model '{embedder_model}' --embedder_model_custom '{embedder_model_custom}'"
os.system(command)
return f"Inference completed. Output saved to {output_path}"
with gr.Blocks() as demo:
gr.Markdown("# Run Inference")
with gr.Row():
model_name = gr.Textbox(label="Model Name")
input_path = gr.Textbox(label="Input Path")
output_path = gr.Textbox(label="Output Path", value="/content/output.wav")
export_format = gr.Dropdown(['WAV', 'MP3', 'FLAC', 'OGG', 'M4A'], label="Export Format")
f0_method = gr.Dropdown(["crepe", "crepe-tiny", "rmvpe", "fcpe", "hybrid[rmvpe+fcpe]"], label="F0 Method")
with gr.Row():
f0_up_key = gr.Slider(-24, 24, step=1, label="F0 Up Key")
filter_radius = gr.Slider(0, 10, step=1, label="Filter Radius")
with gr.Row():
rms_mix_rate = gr.Slider(0.0, 1.0, step=0.1, label="RMS Mix Rate")
protect = gr.Slider(0.0, 0.5, step=0.1, label="Protect")
with gr.Row():
index_rate = gr.Slider(0.0, 1.0, step=0.1, label="Index Rate")
hop_length = gr.Slider(1, 512, step=1, label="Hop Length")
clean_strength = gr.Slider(0.0, 1.0, step=0.1, label="Clean Strength")
split_audio = gr.Checkbox(label="Split Audio")
clean_audio = gr.Checkbox(label="Clean Audio")
f0_autotune = gr.Checkbox(label="F0 AutoTune")
formant_shift = gr.Checkbox(label="Formant Shift")
with gr.Row():
formant_qfrency = gr.Slider(1.0, 16.0, step=0.1, label="Formant Frequency")
formant_timbre = gr.Slider(1.0, 16.0, step=0.1, label="Formant Timbre")
embedder_model = gr.Dropdown(["contentvec", "chinese-hubert-base", "japanese-hubert-base", "korean-hubert-base", "custom"], label="Embedder Model")
embedder_model_custom = gr.Textbox(label="Custom Embedder Model")
submit = gr.Button("Run Inference")
output = gr.Textbox(label="Output Log")
submit.click(run_inference, inputs=[model_name, input_path, output_path, export_format, f0_method, f0_up_key,
filter_radius, rms_mix_rate, protect, index_rate, hop_length, clean_strength,
split_audio, clean_audio, f0_autotune, formant_shift, formant_qfrency,
formant_timbre, embedder_model, embedder_model_custom], outputs=output)
demo.launch()