File size: 1,705 Bytes
4e32610
 
 
 
 
 
04a6916
4e32610
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4f812c8
4e32610
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62c3e5f
4e32610
 
 
 
 
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
from pytube import YouTube
import ffmpeg
from gradio_client import Client
import subprocess
import gradio as gr

client = Client("abidlabs/music-separation")

placeholder_url = "https://www.youtube.com/watch?v=bfATETsvqt4&ab_channel=MiniMuslims"
placeholder_file = "example_acapella_video.mp4"

def acapellify(url):
    if url == placeholder_url:
        return placeholder_file
    
    yt = YouTube(url)
    try:
        video = yt.streams.get_highest_resolution()
        video.download(max_retries=5)
    except:
        raise gr.Error("YouTube video could not be downloaded. Try clicking Submit again and make sure that the URL is correct.")

    video_path = video.get_file_path()

    subprocess.run(['ffmpeg', '-i', video_path, '-vn', '-c:a', 'copy', 'audio.m4a', '-y'])

    result = client.predict(
        'audio.m4a',
        api_name="/predict"
    )

    subprocess.call(['ffmpeg', '-y', '-i', video_path, '-i', result[0], '-map', '0:v', '-map', '1:a', '-c:v', 'copy', '-c:a', 'aac', '-strict', 'experimental', 'acapella_video.mp4'])

    return "acapella_video.mp4"

io = gr.Interface(acapellify, gr.Textbox(label="URL to YouTube video", value=placeholder_url), gr.Video(label="Acapella output"))

with gr.Blocks() as demo:
    gr.Markdown("# Acapellify: Get a Vocals-only from any YouTube Video in 1 Click")
    with gr.Row():
        with gr.Column():
            gr.Markdown("**Example Original Video**")
            gr.Video("old_video.mp4")
        with gr.Column():
            gr.Markdown("**Example Acapella Video**")
            gr.Video(placeholder_file)   

    gr.Markdown("**Try it yourself:** (for now, I recommend short videos <3 minutes)")
    io.render()
    
demo.launch()