Eddycrack864 commited on
Commit
486ccbd
1 Parent(s): 32d05d4

Separation by link

Browse files

Users 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 separated.

Files changed (2) hide show
  1. app.py +110 -1
  2. requirements.txt +2 -1
app.py CHANGED
@@ -2,7 +2,10 @@ import os
2
  import re
3
  import random
4
  from scipy.io.wavfile import write
 
 
5
  import gradio as gr
 
6
  import spaces
7
 
8
  roformer_models = {
@@ -121,6 +124,26 @@ demucs_overlap_values = [
121
  '0.99',
122
  ]
123
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
  @spaces.GPU(duration=300)
125
  def roformer_separator(roformer_audio, roformer_model, roformer_output_format, roformer_overlap, roformer_segment_size):
126
  files_list = []
@@ -286,6 +309,23 @@ with gr.Blocks(theme="NoCrypt/[email protected]", title="🎵 UVR5 UI 🎵") as app:
286
  type = "numpy",
287
  interactive = True
288
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
289
  with gr.Row():
290
  roformer_button = gr.Button("Separate!", variant = "primary")
291
  with gr.Row():
@@ -347,6 +387,23 @@ with gr.Blocks(theme="NoCrypt/[email protected]", title="🎵 UVR5 UI 🎵") as app:
347
  type = "numpy",
348
  interactive = True
349
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
350
  with gr.Row():
351
  mdx23c_button = gr.Button("Separate!", variant = "primary")
352
  with gr.Row():
@@ -405,6 +462,23 @@ with gr.Blocks(theme="NoCrypt/[email protected]", title="🎵 UVR5 UI 🎵") as app:
405
  type = "numpy",
406
  interactive = True
407
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
408
  with gr.Row():
409
  mdxnet_button = gr.Button("Separate!", variant = "primary")
410
  with gr.Row():
@@ -471,6 +545,23 @@ with gr.Blocks(theme="NoCrypt/[email protected]", title="🎵 UVR5 UI 🎵") as app:
471
  type = "numpy",
472
  interactive = True
473
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
474
  with gr.Row():
475
  vrarch_button = gr.Button("Separate!", variant = "primary")
476
  with gr.Row():
@@ -523,6 +614,23 @@ with gr.Blocks(theme="NoCrypt/[email protected]", title="🎵 UVR5 UI 🎵") as app:
523
  type = "numpy",
524
  interactive = True
525
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
526
  with gr.Row():
527
  demucs_button = gr.Button("Separate!", variant = "primary")
528
  with gr.Row():
@@ -563,7 +671,8 @@ with gr.Blocks(theme="NoCrypt/[email protected]", title="🎵 UVR5 UI 🎵") as app:
563
  * Special thanks to [Ilaria](https://github.com/TheStingerX) for hosting this space and help.
564
  * Thanks to [Mikus](https://github.com/cappuch) for the help with the code.
565
  * Thanks to [Nick088](https://huggingface.co/Nick088) for the help to fix roformers.
566
- * Improvements by [Blane187](https://huggingface.co/Blane187).
 
567
 
568
  You can donate to the original UVR5 project here:
569
  [!["Buy Me A Coffee"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/uvr5)
 
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 spaces
10
 
11
  roformer_models = {
 
124
  '0.99',
125
  ]
126
 
127
+ @spaces.GPU(duration=300)
128
+ def download_audio(url):
129
+ ydl_opts = {
130
+ 'format': 'bestaudio/best',
131
+ 'outtmpl': 'ytdl/%(title)s.%(ext)s',
132
+ 'postprocessors': [{
133
+ 'key': 'FFmpegExtractAudio',
134
+ 'preferredcodec': 'wav',
135
+ 'preferredquality': '192',
136
+ }],
137
+ }
138
+
139
+ with yt_dlp.YoutubeDL(ydl_opts) as ydl:
140
+ info_dict = ydl.extract_info(url, download=True)
141
+ file_path = ydl.prepare_filename(info_dict).rsplit('.', 1)[0] + '.wav'
142
+ sample_rate, audio_data = read(file_path)
143
+ audio_array = np.asarray(audio_data, dtype=np.int16)
144
+
145
+ return sample_rate, audio_array
146
+
147
  @spaces.GPU(duration=300)
148
  def roformer_separator(roformer_audio, roformer_model, roformer_output_format, roformer_overlap, roformer_segment_size):
149
  files_list = []
 
309
  type = "numpy",
310
  interactive = True
311
  )
312
+ with gr.Accordion("Separation by Link", open = False):
313
+ with gr.Row():
314
+ roformer_link = gr.Textbox(
315
+ label = "Link",
316
+ placeholder = "Paste the link here",
317
+ interactive = True
318
+ )
319
+ with gr.Row():
320
+ 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)")
321
+ with gr.Row():
322
+ roformer_download_button = gr.Button(
323
+ "Download!",
324
+ variant = "primary"
325
+ )
326
+
327
+ roformer_download_button.click(download_audio, [roformer_link], [roformer_audio])
328
+
329
  with gr.Row():
330
  roformer_button = gr.Button("Separate!", variant = "primary")
331
  with gr.Row():
 
387
  type = "numpy",
388
  interactive = True
389
  )
390
+ with gr.Accordion("Separation by Link", open = False):
391
+ with gr.Row():
392
+ mdx23c_link = gr.Textbox(
393
+ label = "Link",
394
+ placeholder = "Paste the link here",
395
+ interactive = True
396
+ )
397
+ with gr.Row():
398
+ 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)")
399
+ with gr.Row():
400
+ mdx23c_download_button = gr.Button(
401
+ "Download!",
402
+ variant = "primary"
403
+ )
404
+
405
+ mdx23c_download_button.click(download_audio, [mdx23c_link], [mdx23c_audio])
406
+
407
  with gr.Row():
408
  mdx23c_button = gr.Button("Separate!", variant = "primary")
409
  with gr.Row():
 
462
  type = "numpy",
463
  interactive = True
464
  )
465
+ with gr.Accordion("Separation by Link", open = False):
466
+ with gr.Row():
467
+ mdxnet_link = gr.Textbox(
468
+ label = "Link",
469
+ placeholder = "Paste the link here",
470
+ interactive = True
471
+ )
472
+ with gr.Row():
473
+ 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)")
474
+ with gr.Row():
475
+ mdxnet_download_button = gr.Button(
476
+ "Download!",
477
+ variant = "primary"
478
+ )
479
+
480
+ mdxnet_download_button.click(download_audio, [mdxnet_link], [mdxnet_audio])
481
+
482
  with gr.Row():
483
  mdxnet_button = gr.Button("Separate!", variant = "primary")
484
  with gr.Row():
 
545
  type = "numpy",
546
  interactive = True
547
  )
548
+ with gr.Accordion("Separation by Link", open = False):
549
+ with gr.Row():
550
+ vrarch_link = gr.Textbox(
551
+ label = "Link",
552
+ placeholder = "Paste the link here",
553
+ interactive = True
554
+ )
555
+ with gr.Row():
556
+ 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)")
557
+ with gr.Row():
558
+ vrarch_download_button = gr.Button(
559
+ "Download!",
560
+ variant = "primary"
561
+ )
562
+
563
+ vrarch_download_button.click(download_audio, [vrarch_link], [vrarch_audio])
564
+
565
  with gr.Row():
566
  vrarch_button = gr.Button("Separate!", variant = "primary")
567
  with gr.Row():
 
614
  type = "numpy",
615
  interactive = True
616
  )
617
+ with gr.Accordion("Separation by Link", open = False):
618
+ with gr.Row():
619
+ demucs_link = gr.Textbox(
620
+ label = "Link",
621
+ placeholder = "Paste the link here",
622
+ interactive = True
623
+ )
624
+ with gr.Row():
625
+ 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)")
626
+ with gr.Row():
627
+ demucs_download_button = gr.Button(
628
+ "Download!",
629
+ variant = "primary"
630
+ )
631
+
632
+ demucs_download_button.click(download_audio, [demucs_link], [demucs_audio])
633
+
634
  with gr.Row():
635
  demucs_button = gr.Button("Separate!", variant = "primary")
636
  with gr.Row():
 
671
  * Special thanks to [Ilaria](https://github.com/TheStingerX) for hosting this space and help.
672
  * Thanks to [Mikus](https://github.com/cappuch) for the help with the code.
673
  * Thanks to [Nick088](https://huggingface.co/Nick088) for the help to fix roformers.
674
+ * Thanks to [yt_dlp](https://github.com/yt-dlp/yt-dlp) devs.
675
+ * Separation by link source code and improvements by [Blane187](https://huggingface.co/Blane187).
676
 
677
  You can donate to the original UVR5 project here:
678
  [!["Buy Me A Coffee"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/uvr5)
requirements.txt CHANGED
@@ -1,3 +1,4 @@
1
  numpy==1.25.2
2
  audio-separator[gpu]==0.17.5
3
- scipy
 
 
1
  numpy==1.25.2
2
  audio-separator[gpu]==0.17.5
3
+ scipy
4
+ yt_dlp