Spaces:
Runtime error
Runtime error
inference by link
Browse filesUsers can paste the link to the video/audio from many sites (supported by yt_dlp). Complete list [here](https://github.com/yt-dlp/yt-dlp/blob/master/supportedsites.md)
The audio will be downloaded to the input and can then be infered.
- app/infer.py +33 -0
app/infer.py
CHANGED
@@ -10,6 +10,26 @@ import soundfile as sf
|
|
10 |
from zerorvc import RVC
|
11 |
from .zero import zero
|
12 |
from .model import device
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
|
15 |
@zero(duration=120)
|
@@ -26,6 +46,7 @@ def infer(
|
|
26 |
ext = Path(original_audio).suffix
|
27 |
original_audio_hashed = os.path.join(exp_dir, f"{original_audio_hash}{ext}")
|
28 |
shutil.copy(original_audio, original_audio_hashed)
|
|
|
29 |
|
30 |
out = os.path.join("separated", "htdemucs", original_audio_hash, "vocals.wav")
|
31 |
if not os.path.exists(out):
|
@@ -81,6 +102,18 @@ class InferenceTab:
|
|
81 |
type="filepath",
|
82 |
show_download_button=True,
|
83 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
|
85 |
with gr.Column():
|
86 |
self.pitch_mod = gr.Slider(
|
|
|
10 |
from zerorvc import RVC
|
11 |
from .zero import zero
|
12 |
from .model import device
|
13 |
+
import yt_dlp
|
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 |
@zero(duration=120)
|
|
|
46 |
ext = Path(original_audio).suffix
|
47 |
original_audio_hashed = os.path.join(exp_dir, f"{original_audio_hash}{ext}")
|
48 |
shutil.copy(original_audio, original_audio_hashed)
|
49 |
+
|
50 |
|
51 |
out = os.path.join("separated", "htdemucs", original_audio_hash, "vocals.wav")
|
52 |
if not os.path.exists(out):
|
|
|
102 |
type="filepath",
|
103 |
show_download_button=True,
|
104 |
)
|
105 |
+
with gr.Accordion("inference by Link",open=False):
|
106 |
+
with gr.Row():
|
107 |
+
youtube_link = gr.Textbox(
|
108 |
+
label = "Link",
|
109 |
+
placeholder = "Paste the link here",
|
110 |
+
interactive = True
|
111 |
+
)
|
112 |
+
with gr.Row():
|
113 |
+
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)")
|
114 |
+
with gr.Row():
|
115 |
+
download_button = gr.Button("Download!",variant = "primary")
|
116 |
+
download_button.click(download_audio, [youtube_link], [self.original_audio])
|
117 |
|
118 |
with gr.Column():
|
119 |
self.pitch_mod = gr.Slider(
|