Next commited on
Commit
688204f
·
verified ·
1 Parent(s): 8e8323c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -6
app.py CHANGED
@@ -1,6 +1,9 @@
1
  import os
2
  from scipy.io.wavfile import write
3
  import gradio as gr
 
 
 
4
 
5
  def separator(audio):
6
  os.makedirs("output", exist_ok=True)
@@ -20,12 +23,50 @@ def separator(audio):
20
 
21
  return files
22
 
23
- with gr.Blocks() as demo:
24
- audio_input = gr.Audio(type="numpy", label="Input")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
- output1 = gr.Audio(type="filepath", label="Stem 1", interactive=False)
27
- output2 = gr.Audio(type="filepath", label="Stem 2", interactive=False)
28
- submit_button = gr.Button("Separate")
29
- submit_button.click(separator, inputs=audio_input, outputs=[output1, output2])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
  demo.launch()
 
1
  import os
2
  from scipy.io.wavfile import write
3
  import gradio as gr
4
+ import yt_dlp
5
+
6
+ os.makedirs("ytdl", exist_ok=True)
7
 
8
  def separator(audio):
9
  os.makedirs("output", exist_ok=True)
 
23
 
24
  return files
25
 
26
+
27
+
28
+
29
+ def download_audio(url):
30
+ ydl_opts = {
31
+ 'format': 'bestaudio/best',
32
+ 'outtmpl': 'ytdl/%(title)s.%(ext)s',
33
+ 'postprocessors': [{
34
+ 'key': 'FFmpegExtractAudio',
35
+ 'preferredcodec': 'mp3',
36
+ 'preferredquality': '192',
37
+ }],
38
+ }
39
+
40
+ with yt_dlp.YoutubeDL(ydl_opts) as ydl:
41
+ info_dict = ydl.extract_info(url, download=True)
42
+ file_path = ydl.prepare_filename(info_dict).rsplit('.', 1)[0] + '.mp3'
43
+ return file_path
44
+
45
+ def download_and_show(url):
46
+ file_path = download_audio(url)
47
+ return file_path
48
 
49
+
50
+ with gr.Blocks() as demo:
51
+ with gr.Tab("Esparator"):
52
+ audio_input = gr.Audio(type="numpy", label="Input")
53
+ output1 = gr.Audio(type="filepath", label="Stem 1", interactive=False)
54
+ output2 = gr.Audio(type="filepath", label="Stem 2", interactive=False)
55
+ submit_button = gr.Button("Separate")
56
+ submit_button.click(separator, inputs=audio_input, outputs=[output1, output2])
57
+ with gr.Tab("Download youtube audio for esparation"):
58
+ url = gr.Textbox(label="Url To youtube")
59
+ download = gr.Button("download")
60
+ download.click
61
+ (
62
+ download_and_show,
63
+ inputs=[
64
+ url,
65
+ ],
66
+ outputs=
67
+ [
68
+ audio_input,
69
+ ],
70
+ )
71
 
72
  demo.launch()