Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,47 @@
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
-
from lib.infer import infer_audio
|
| 4 |
from pydub import AudioSegment
|
| 5 |
-
import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
def process_audio(MODEL_NAME, SOUND_PATH, F0_CHANGE, F0_METHOD, MIN_PITCH, MAX_PITCH, CREPE_HOP_LENGTH, INDEX_RATE,
|
| 9 |
FILTER_RADIUS, RMS_MIX_RATE, PROTECT, SPLIT_INFER, MIN_SILENCE, SILENCE_THRESHOLD, SEEK_STEP,
|
| 10 |
KEEP_SILENCE, FORMANT_SHIFT, QUEFRENCY, TIMBRE, F0_AUTOTUNE, OUTPUT_FORMAT, upload_audio=None):
|
|
@@ -45,30 +82,52 @@ def process_audio(MODEL_NAME, SOUND_PATH, F0_CHANGE, F0_METHOD, MIN_PITCH, MAX_P
|
|
| 45 |
OUTPUT_FORMAT
|
| 46 |
)
|
| 47 |
|
| 48 |
-
# Output the inferred audio file
|
| 49 |
return inferred_audio
|
| 50 |
|
| 51 |
|
| 52 |
-
# Gradio Blocks Interface
|
| 53 |
-
with gr.Blocks(
|
| 54 |
-
gr.Markdown("#
|
| 55 |
-
|
| 56 |
-
|
| 57 |
with gr.Row():
|
| 58 |
-
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
with gr.Row():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
SOUND_PATH = gr.Textbox(label="Audio Path (Optional)", placeholder="Leave blank to upload audio")
|
| 62 |
upload_audio = gr.File(label="Upload Audio", type='filepath', file_types=["audio"])
|
| 63 |
-
|
| 64 |
with gr.Row():
|
| 65 |
F0_CHANGE = gr.Number(label="Pitch Change (semitones)", value=0)
|
| 66 |
-
F0_METHOD = gr.Dropdown(choices=["crepe", "harvest", "mangio-crepe", "rmvpe", "rmvpe+", "fcpe",
|
| 67 |
"hybrid[mangio-crepe+rmvpe]", "hybrid[mangio-crepe+fcpe]",
|
| 68 |
"hybrid[rmvpe+fcpe]", "hybrid[mangio-crepe+rmvpe+fcpe]"],
|
| 69 |
label="F0 Method", value="fcpe")
|
| 70 |
-
|
| 71 |
-
# Other Settings
|
| 72 |
with gr.Row():
|
| 73 |
MIN_PITCH = gr.Textbox(label="Min Pitch", value="50")
|
| 74 |
MAX_PITCH = gr.Textbox(label="Max Pitch", value="1100")
|
|
@@ -77,7 +136,7 @@ with gr.Blocks(tite="Hex RVC") as app:
|
|
| 77 |
FILTER_RADIUS = gr.Number(label="Filter Radius", value=3)
|
| 78 |
RMS_MIX_RATE = gr.Slider(label="RMS Mix Rate", minimum=0, maximum=1, value=0.25)
|
| 79 |
PROTECT = gr.Slider(label="Protect", minimum=0, maximum=1, value=0.33)
|
| 80 |
-
|
| 81 |
with gr.Accordion("Advanced Settings", open=False):
|
| 82 |
SPLIT_INFER = gr.Checkbox(label="Enable Split Inference", value=False)
|
| 83 |
MIN_SILENCE = gr.Number(label="Min Silence (ms)", value=500)
|
|
@@ -88,13 +147,11 @@ with gr.Blocks(tite="Hex RVC") as app:
|
|
| 88 |
QUEFRENCY = gr.Number(label="Quefrency", value=0)
|
| 89 |
TIMBRE = gr.Number(label="Timbre", value=1)
|
| 90 |
F0_AUTOTUNE = gr.Checkbox(label="Enable F0 Autotune", value=False)
|
| 91 |
-
# Output Settings
|
| 92 |
OUTPUT_FORMAT = gr.Dropdown(choices=["wav", "flac", "mp3"], label="Output Format", value="wav")
|
|
|
|
| 93 |
run_button = gr.Button("Run Inference")
|
| 94 |
-
# Audio Output
|
| 95 |
output_audio = gr.Audio(label="Generated Audio", type='filepath')
|
| 96 |
-
|
| 97 |
-
# Run the process_audio function on button click
|
| 98 |
run_button.click(
|
| 99 |
process_audio,
|
| 100 |
inputs=[MODEL_NAME, SOUND_PATH, F0_CHANGE, F0_METHOD, MIN_PITCH, MAX_PITCH, CREPE_HOP_LENGTH, INDEX_RATE,
|
|
@@ -104,4 +161,4 @@ with gr.Blocks(tite="Hex RVC") as app:
|
|
| 104 |
)
|
| 105 |
|
| 106 |
# Launch the Gradio app
|
| 107 |
-
app.launch()
|
|
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
|
|
|
| 3 |
from pydub import AudioSegment
|
| 4 |
+
from audio_separator.separator import Separator
|
| 5 |
+
from lib.infer import infer_audio
|
| 6 |
+
|
| 7 |
+
# Define a function to handle the entire separation process
|
| 8 |
+
def separate_audio(input_audio, output_dir, model_voc_inst, model_deecho, model_back_voc):
|
| 9 |
+
# Create output directory if it doesn't exist
|
| 10 |
+
if not os.path.exists(output_dir):
|
| 11 |
+
os.makedirs(output_dir)
|
| 12 |
+
|
| 13 |
+
separator = Separator(output_dir=output_dir)
|
| 14 |
+
|
| 15 |
+
# Define output files
|
| 16 |
+
vocals = os.path.join(output_dir, 'Vocals.wav')
|
| 17 |
+
instrumental = os.path.join(output_dir, 'Instrumental.wav')
|
| 18 |
+
vocals_reverb = os.path.join(output_dir, 'Vocals (Reverb).wav')
|
| 19 |
+
vocals_no_reverb = os.path.join(output_dir, 'Vocals (No Reverb).wav')
|
| 20 |
+
lead_vocals = os.path.join(output_dir, 'Lead Vocals.wav')
|
| 21 |
+
backing_vocals = os.path.join(output_dir, 'Backing Vocals.wav')
|
| 22 |
+
|
| 23 |
+
# Splitting a track into Vocal and Instrumental
|
| 24 |
+
separator.load_model(model_filename=model_voc_inst)
|
| 25 |
+
voc_inst = separator.separate(input_audio)
|
| 26 |
+
os.rename(os.path.join(output_dir, voc_inst[0]), instrumental) # Rename to “Instrumental.wav”
|
| 27 |
+
os.rename(os.path.join(output_dir, voc_inst[1]), vocals) # Rename to “Vocals.wav”
|
| 28 |
+
|
| 29 |
+
# Applying DeEcho-DeReverb to Vocals
|
| 30 |
+
separator.load_model(model_filename=model_deecho)
|
| 31 |
+
voc_no_reverb = separator.separate(vocals)
|
| 32 |
+
os.rename(os.path.join(output_dir, voc_no_reverb[0]), vocals_no_reverb) # Rename to “Vocals (No Reverb).wav”
|
| 33 |
+
os.rename(os.path.join(output_dir, voc_no_reverb[1]), vocals_reverb) # Rename to “Vocals (Reverb).wav”
|
| 34 |
|
| 35 |
+
# Separating Back Vocals from Main Vocals
|
| 36 |
+
separator.load_model(model_filename=model_back_voc)
|
| 37 |
+
backing_voc = separator.separate(vocals_no_reverb)
|
| 38 |
+
os.rename(os.path.join(output_dir, backing_voc[0]), backing_vocals) # Rename to “Backing Vocals.wav”
|
| 39 |
+
os.rename(os.path.join(output_dir, backing_voc[1]), lead_vocals) # Rename to “Lead Vocals.wav”
|
| 40 |
+
|
| 41 |
+
return instrumental, vocals, vocals_reverb, vocals_no_reverb, lead_vocals, backing_vocals
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
# Main function to process audio (Inference)
|
| 45 |
def process_audio(MODEL_NAME, SOUND_PATH, F0_CHANGE, F0_METHOD, MIN_PITCH, MAX_PITCH, CREPE_HOP_LENGTH, INDEX_RATE,
|
| 46 |
FILTER_RADIUS, RMS_MIX_RATE, PROTECT, SPLIT_INFER, MIN_SILENCE, SILENCE_THRESHOLD, SEEK_STEP,
|
| 47 |
KEEP_SILENCE, FORMANT_SHIFT, QUEFRENCY, TIMBRE, F0_AUTOTUNE, OUTPUT_FORMAT, upload_audio=None):
|
|
|
|
| 82 |
OUTPUT_FORMAT
|
| 83 |
)
|
| 84 |
|
|
|
|
| 85 |
return inferred_audio
|
| 86 |
|
| 87 |
|
| 88 |
+
# Gradio Blocks Interface with Tabs
|
| 89 |
+
with gr.Blocks(title="Hex RVC") as app:
|
| 90 |
+
gr.Markdown("# Hex RVC")
|
| 91 |
+
|
| 92 |
+
with gr.Tab("Audio Separation"):
|
| 93 |
with gr.Row():
|
| 94 |
+
input_audio = gr.Audio(source="upload", type="filepath", label="Upload Audio File")
|
| 95 |
+
output_dir = gr.Textbox(value="/content/output", label="Output Directory")
|
| 96 |
+
|
| 97 |
+
with gr.Row():
|
| 98 |
+
model_voc_inst = gr.Textbox(value='model_bs_roformer_ep_317_sdr_12.9755.ckpt', label="Vocal & Instrumental Model")
|
| 99 |
+
model_deecho = gr.Textbox(value='UVR-DeEcho-DeReverb.pth', label="DeEcho-DeReverb Model")
|
| 100 |
+
model_back_voc = gr.Textbox(value='mel_band_roformer_karaoke_aufr33_viperx_sdr_10.1956.ckpt', label="Backing Vocals Model")
|
| 101 |
+
|
| 102 |
+
separate_button = gr.Button("Separate Audio")
|
| 103 |
+
|
| 104 |
with gr.Row():
|
| 105 |
+
instrumental_out = gr.Audio(label="Instrumental")
|
| 106 |
+
vocals_out = gr.Audio(label="Vocals")
|
| 107 |
+
vocals_reverb_out = gr.Audio(label="Vocals (Reverb)")
|
| 108 |
+
vocals_no_reverb_out = gr.Audio(label="Vocals (No Reverb)")
|
| 109 |
+
lead_vocals_out = gr.Audio(label="Lead Vocals")
|
| 110 |
+
backing_vocals_out = gr.Audio(label="Backing Vocals")
|
| 111 |
+
|
| 112 |
+
separate_button.click(
|
| 113 |
+
separate_audio,
|
| 114 |
+
inputs=[input_audio, output_dir, model_voc_inst, model_deecho, model_back_voc],
|
| 115 |
+
outputs=[instrumental_out, vocals_out, vocals_reverb_out, vocals_no_reverb_out, lead_vocals_out, backing_vocals_out]
|
| 116 |
+
)
|
| 117 |
+
|
| 118 |
+
with gr.Tab("Inference"):
|
| 119 |
+
with gr.Row():
|
| 120 |
+
MODEL_NAME = gr.Textbox(label="Model Name", placeholder="Enter model name")
|
| 121 |
SOUND_PATH = gr.Textbox(label="Audio Path (Optional)", placeholder="Leave blank to upload audio")
|
| 122 |
upload_audio = gr.File(label="Upload Audio", type='filepath', file_types=["audio"])
|
| 123 |
+
|
| 124 |
with gr.Row():
|
| 125 |
F0_CHANGE = gr.Number(label="Pitch Change (semitones)", value=0)
|
| 126 |
+
F0_METHOD = gr.Dropdown(choices=["crepe", "harvest", "mangio-crepe", "rmvpe", "rmvpe+", "fcpe",
|
| 127 |
"hybrid[mangio-crepe+rmvpe]", "hybrid[mangio-crepe+fcpe]",
|
| 128 |
"hybrid[rmvpe+fcpe]", "hybrid[mangio-crepe+rmvpe+fcpe]"],
|
| 129 |
label="F0 Method", value="fcpe")
|
| 130 |
+
|
|
|
|
| 131 |
with gr.Row():
|
| 132 |
MIN_PITCH = gr.Textbox(label="Min Pitch", value="50")
|
| 133 |
MAX_PITCH = gr.Textbox(label="Max Pitch", value="1100")
|
|
|
|
| 136 |
FILTER_RADIUS = gr.Number(label="Filter Radius", value=3)
|
| 137 |
RMS_MIX_RATE = gr.Slider(label="RMS Mix Rate", minimum=0, maximum=1, value=0.25)
|
| 138 |
PROTECT = gr.Slider(label="Protect", minimum=0, maximum=1, value=0.33)
|
| 139 |
+
|
| 140 |
with gr.Accordion("Advanced Settings", open=False):
|
| 141 |
SPLIT_INFER = gr.Checkbox(label="Enable Split Inference", value=False)
|
| 142 |
MIN_SILENCE = gr.Number(label="Min Silence (ms)", value=500)
|
|
|
|
| 147 |
QUEFRENCY = gr.Number(label="Quefrency", value=0)
|
| 148 |
TIMBRE = gr.Number(label="Timbre", value=1)
|
| 149 |
F0_AUTOTUNE = gr.Checkbox(label="Enable F0 Autotune", value=False)
|
|
|
|
| 150 |
OUTPUT_FORMAT = gr.Dropdown(choices=["wav", "flac", "mp3"], label="Output Format", value="wav")
|
| 151 |
+
|
| 152 |
run_button = gr.Button("Run Inference")
|
|
|
|
| 153 |
output_audio = gr.Audio(label="Generated Audio", type='filepath')
|
| 154 |
+
|
|
|
|
| 155 |
run_button.click(
|
| 156 |
process_audio,
|
| 157 |
inputs=[MODEL_NAME, SOUND_PATH, F0_CHANGE, F0_METHOD, MIN_PITCH, MAX_PITCH, CREPE_HOP_LENGTH, INDEX_RATE,
|
|
|
|
| 161 |
)
|
| 162 |
|
| 163 |
# Launch the Gradio app
|
| 164 |
+
app.launch()
|