Spaces:
Runtime error
Runtime error
requirements.txt
Browse filesgradio>=3.0
moviepy==1.0.3
numpy
app.py
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import os
|
3 |
+
import numpy as np
|
4 |
+
from moviepy.editor import *
|
5 |
+
import tempfile
|
6 |
+
|
7 |
+
def generate_music_video(audio_path, style, duration, intensity):
|
8 |
+
# Audio processing
|
9 |
+
audio = AudioFileClip(audio_path)
|
10 |
+
audio = audio.subclip(0, duration)
|
11 |
+
|
12 |
+
# Visual generation
|
13 |
+
waveform = audio.make_frame_array()
|
14 |
+
waveform_normalized = waveform / np.max(np.abs(waveform))
|
15 |
+
|
16 |
+
# Create dynamic visualization
|
17 |
+
clips = []
|
18 |
+
for i in range(0, len(waveform_normalized), 1000):
|
19 |
+
frame = np.zeros((720, 1280, 3))
|
20 |
+
x = int(640 + waveform_normalized[i] * 600 * intensity)
|
21 |
+
y = 360 + int(np.sin(i/1000) * 100 * intensity)
|
22 |
+
|
23 |
+
# Style-based coloring
|
24 |
+
if style == "Cyberpunk":
|
25 |
+
color = [0, 1, 1] # Cyan
|
26 |
+
elif style == "Retro Wave":
|
27 |
+
color = [1, 0, 1] # Magenta
|
28 |
+
elif style == "Neon Glow":
|
29 |
+
color = [0.5, 1, 0] # Lime
|
30 |
+
else:
|
31 |
+
color = [1, 1, 0] # Yellow
|
32 |
+
|
33 |
+
# Animated elements
|
34 |
+
frame[300:420, x-20:x+20] = color
|
35 |
+
frame[y-50:y+50, 600:680] = color
|
36 |
+
|
37 |
+
clips.append(ImageClip(frame).set_duration(0.04))
|
38 |
+
|
39 |
+
video = concatenate_videoclips(clips)
|
40 |
+
video = video.set_audio(audio)
|
41 |
+
|
42 |
+
output_path = os.path.join(tempfile.gettempdir(), "music_video.mp4")
|
43 |
+
video.write_videofile(output_path, fps=24)
|
44 |
+
return output_path
|
45 |
+
|
46 |
+
with gr.Blocks(theme=gr.themes.Soft(), css="footer {visibility: hidden}") as demo:
|
47 |
+
gr.Markdown("""# 🎶 AI Music Video Generator
|
48 |
+
*Transform your audio into visual experiences*""")
|
49 |
+
|
50 |
+
with gr.Row():
|
51 |
+
with gr.Column(scale=1):
|
52 |
+
gr.Image("banner.png", show_label=False)
|
53 |
+
audio_input = gr.Audio(label="Upload MP3/WAV", type="filepath")
|
54 |
+
style_select = gr.Dropdown(
|
55 |
+
choices=["Cyberpunk", "Retro Wave", "Neon Glow", "Nature", "Abstract"],
|
56 |
+
label="Visual Style",
|
57 |
+
value="Cyberpunk"
|
58 |
+
)
|
59 |
+
duration_slider = gr.Slider(10, 300, value=60, label="Duration (seconds)")
|
60 |
+
intensity_slider = gr.Slider(0.5, 2.0, value=1.0, label="Effect Intensity")
|
61 |
+
generate_btn = gr.Button("Generate Video 🎬", variant="primary")
|
62 |
+
|
63 |
+
with gr.Column(scale=2):
|
64 |
+
video_output = gr.Video(label="Your Music Video", interactive=False)
|
65 |
+
gr.Markdown("Share your creation: [Twitter] [Facebook] [Instagram]")
|
66 |
+
|
67 |
+
generate_btn.click(
|
68 |
+
fn=generate_music_video,
|
69 |
+
inputs=[audio_input, style_select, duration_slider, intensity_slider],
|
70 |
+
outputs=[video_output]
|
71 |
+
)
|
72 |
+
|
73 |
+
if __name__ == "__main__":
|
74 |
+
demo.launch()
|