Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pytube import YouTube
|
2 |
+
import ffmpeg
|
3 |
+
from gradio_client import Client
|
4 |
+
import subprocess
|
5 |
+
import gradio as gr
|
6 |
+
|
7 |
+
client = Client("abidlabs/Acapellify")
|
8 |
+
|
9 |
+
placeholder_url = "https://www.youtube.com/watch?v=bfATETsvqt4&ab_channel=MiniMuslims"
|
10 |
+
placeholder_file = "example_acapella_video.mp4"
|
11 |
+
|
12 |
+
def acapellify(url):
|
13 |
+
if url == placeholder_url:
|
14 |
+
return placeholder_file
|
15 |
+
|
16 |
+
yt = YouTube(url)
|
17 |
+
try:
|
18 |
+
video = yt.streams.get_highest_resolution()
|
19 |
+
video.download(max_retries=5)
|
20 |
+
except:
|
21 |
+
raise gr.Error("YouTube video could not be downloaded. Try clicking Submit again and make sure that the URL is correct.")
|
22 |
+
|
23 |
+
video_path = video.get_file_path()
|
24 |
+
|
25 |
+
(
|
26 |
+
ffmpeg
|
27 |
+
.input(video_path)
|
28 |
+
.audio
|
29 |
+
.output('audio.m4a', format='mp4')
|
30 |
+
.overwrite_output()
|
31 |
+
.run()
|
32 |
+
)
|
33 |
+
|
34 |
+
result = client.predict(
|
35 |
+
'audio.m4a',
|
36 |
+
api_name="/predict"
|
37 |
+
)
|
38 |
+
|
39 |
+
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'])
|
40 |
+
|
41 |
+
return "acapella_video.mp4"
|
42 |
+
|
43 |
+
io = gr.Interface(acapellify, gr.Textbox(label="URL to YouTube video", value=placeholder_url), gr.Video(label="Acapella output"))
|
44 |
+
|
45 |
+
with gr.Blocks() as demo:
|
46 |
+
gr.Markdown("# Acapellify: Get a Vocals-only from any YouTube Video in 1 Click")
|
47 |
+
with gr.Row():
|
48 |
+
with gr.Column():
|
49 |
+
gr.Markdown("**Example Original Video**")
|
50 |
+
gr.Video("old_video.mp4")
|
51 |
+
with gr.Column():
|
52 |
+
gr.Markdown("**Example Acapella Video**")
|
53 |
+
gr.Video("acapella_video.mp4")
|
54 |
+
|
55 |
+
gr.Markdown("**Try it yourself:** (for now, I recommend short videos <3 minutes)")
|
56 |
+
io.render()
|
57 |
+
|
58 |
+
demo.launch()
|