Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,39 @@
|
|
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
|
@@ -89,32 +119,6 @@ def process_audio(MODEL_NAME, SOUND_PATH, F0_CHANGE, F0_METHOD, MIN_PITCH, MAX_P
|
|
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")
|
@@ -160,5 +164,49 @@ with gr.Blocks(title="Hex RVC") as app:
|
|
160 |
outputs=output_audio
|
161 |
)
|
162 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
163 |
# Launch the Gradio app
|
164 |
app.launch()
|
|
|
1 |
import os
|
2 |
+
import re
|
3 |
+
import random
|
4 |
+
from scipy.io.wavfile import write
|
5 |
+
from scipy.io.wavfile import read
|
6 |
+
import numpy as np
|
7 |
import gradio as gr
|
8 |
+
import yt_dlp
|
9 |
+
import subprocess
|
10 |
from pydub import AudioSegment
|
11 |
from audio_separator.separator import Separator
|
12 |
from lib.infer import infer_audio
|
13 |
|
14 |
+
|
15 |
+
def download_audio(url):
|
16 |
+
ydl_opts = {
|
17 |
+
'format': 'bestaudio/best',
|
18 |
+
'outtmpl': 'ytdl/%(title)s.%(ext)s',
|
19 |
+
'postprocessors': [{
|
20 |
+
'key': 'FFmpegExtractAudio',
|
21 |
+
'preferredcodec': 'wav',
|
22 |
+
'preferredquality': '192',
|
23 |
+
}],
|
24 |
+
}
|
25 |
+
|
26 |
+
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
27 |
+
info_dict = ydl.extract_info(url, download=True)
|
28 |
+
file_path = ydl.prepare_filename(info_dict).rsplit('.', 1)[0] + '.wav'
|
29 |
+
sample_rate, audio_data = read(file_path)
|
30 |
+
audio_array = np.asarray(audio_data, dtype=np.int16)
|
31 |
+
|
32 |
+
return sample_rate, audio_array
|
33 |
+
|
34 |
+
|
35 |
+
|
36 |
+
|
37 |
# Define a function to handle the entire separation process
|
38 |
def separate_audio(input_audio, output_dir, model_voc_inst, model_deecho, model_back_voc):
|
39 |
# Create output directory if it doesn't exist
|
|
|
119 |
with gr.Blocks(title="Hex RVC") as app:
|
120 |
gr.Markdown("# Hex RVC")
|
121 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
with gr.Tab("Inference"):
|
123 |
with gr.Row():
|
124 |
MODEL_NAME = gr.Textbox(label="Model Name", placeholder="Enter model name")
|
|
|
164 |
outputs=output_audio
|
165 |
)
|
166 |
|
167 |
+
with gr.Tab("Audio Separation"):
|
168 |
+
with gr.Row():
|
169 |
+
input_audio = gr.Audio(source="upload", type="filepath", label="Upload Audio File")
|
170 |
+
output_dir = gr.Textbox(value="/content/output", label="Output Directory")
|
171 |
+
|
172 |
+
with gr.Accordion("Separation by Link", open = False):
|
173 |
+
with gr.Row():
|
174 |
+
roformer_link = gr.Textbox(
|
175 |
+
label = "Link",
|
176 |
+
placeholder = "Paste the link here",
|
177 |
+
interactive = True
|
178 |
+
)
|
179 |
+
with gr.Row():
|
180 |
+
gr.Markdown("You can paste the link to the video/audio from many sites, check the complete list [here](https://github.com/yt-dlp/yt-dlp/blob/master/supportedsites.md)")
|
181 |
+
with gr.Row():
|
182 |
+
roformer_download_button = gr.Button(
|
183 |
+
"Download!",
|
184 |
+
variant = "primary"
|
185 |
+
)
|
186 |
+
|
187 |
+
roformer_download_button.click(download_audio, [roformer_link], [input_audio])
|
188 |
+
|
189 |
+
with gr.Row():
|
190 |
+
model_voc_inst = gr.Textbox(value='model_bs_roformer_ep_317_sdr_12.9755.ckpt', label="Vocal & Instrumental Model")
|
191 |
+
model_deecho = gr.Textbox(value='UVR-DeEcho-DeReverb.pth', label="DeEcho-DeReverb Model")
|
192 |
+
model_back_voc = gr.Textbox(value='mel_band_roformer_karaoke_aufr33_viperx_sdr_10.1956.ckpt', label="Backing Vocals Model")
|
193 |
+
|
194 |
+
separate_button = gr.Button("Separate Audio")
|
195 |
+
|
196 |
+
with gr.Row():
|
197 |
+
instrumental_out = gr.Audio(label="Instrumental")
|
198 |
+
vocals_out = gr.Audio(label="Vocals")
|
199 |
+
vocals_reverb_out = gr.Audio(label="Vocals (Reverb)")
|
200 |
+
vocals_no_reverb_out = gr.Audio(label="Vocals (No Reverb)")
|
201 |
+
lead_vocals_out = gr.Audio(label="Lead Vocals")
|
202 |
+
backing_vocals_out = gr.Audio(label="Backing Vocals")
|
203 |
+
|
204 |
+
separate_button.click(
|
205 |
+
separate_audio,
|
206 |
+
inputs=[input_audio, output_dir, model_voc_inst, model_deecho, model_back_voc],
|
207 |
+
outputs=[instrumental_out, vocals_out, vocals_reverb_out, vocals_no_reverb_out, lead_vocals_out, backing_vocals_out]
|
208 |
+
)
|
209 |
+
|
210 |
+
|
211 |
# Launch the Gradio app
|
212 |
app.launch()
|