File size: 2,044 Bytes
5f14b33
 
 
688204f
 
 
5f14b33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
688204f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f45e7a3
688204f
 
 
 
f45e7a3
3a53365
f45e7a3
 
3a53365
f45e7a3
 
 
 
688204f
f45e7a3
 
688204f
5f14b33
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import os
from scipy.io.wavfile import write
import gradio as gr
import yt_dlp

os.makedirs("ytdl", exist_ok=True)

def separator(audio):
    os.makedirs("output", exist_ok=True)
    write('test.wav', audio[0], audio[1])
    result = os.system("audio-separator test.wav --model_filename model_bs_roformer_ep_317_sdr_12.9755.ckpt --output_dir=./output --output_format=wav")

    files = [
        "./output/test_(Instrumental)_model_bs_roformer_ep_317_sdr_12.wav",
        "./output/test_(Vocals)_model_bs_roformer_ep_317_sdr_12.wav"
    ]

    for file in files:
        if not os.path.isfile(file):
            print(f"File not found: {file}")
        else:
            print(f"File exists: {file}")

    return files

def download_audio(url):
    ydl_opts = {
        'format': 'bestaudio/best',
        'outtmpl': 'ytdl/%(title)s.%(ext)s',
        'postprocessors': [{
            'key': 'FFmpegExtractAudio',
            'preferredcodec': 'mp3',
            'preferredquality': '192',
        }],
    }

    with yt_dlp.YoutubeDL(ydl_opts) as ydl:
        info_dict = ydl.extract_info(url, download=True)
        file_path = ydl.prepare_filename(info_dict).rsplit('.', 1)[0] + '.mp3'
        return file_path

def download_and_show(url):
    file_path = download_audio(url)
    return file_path

with gr.Blocks() as demo:
    with gr.Tab("Separator"):
        audio_input = gr.Audio(type="numpy", label="Input")
        output1 = gr.Audio(type="filepath", label="Stem 1", interactive=False)
        output2 = gr.Audio(type="filepath", label="Stem 2", interactive=False)
        submit_button = gr.Button("Separate")
        submit_button.click(
            separator, 
            inputs=[audio_input],
            outputs=[output1, output2]
        )
    with gr.Tab("Download YouTube audio for separation"):
        url = gr.Textbox(label="URL to YouTube")
        download = gr.Button("Download")
        download.click(
            download_and_show,
            inputs=[url],
            outputs=[audio_input]
        )

demo.launch()