File size: 2,674 Bytes
0578478
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
68
69
70
71
72
73
74
import gradio as gr
import os
import numpy as np
from moviepy.editor import *
import tempfile

def generate_music_video(audio_path, style, duration, intensity):
    # Audio processing
    audio = AudioFileClip(audio_path)
    audio = audio.subclip(0, duration)
    
    # Visual generation
    waveform = audio.make_frame_array()
    waveform_normalized = waveform / np.max(np.abs(waveform))
    
    # Create dynamic visualization
    clips = []
    for i in range(0, len(waveform_normalized), 1000):
        frame = np.zeros((720, 1280, 3))
        x = int(640 + waveform_normalized[i] * 600 * intensity)
        y = 360 + int(np.sin(i/1000) * 100 * intensity)
        
        # Style-based coloring
        if style == "Cyberpunk":
            color = [0, 1, 1]  # Cyan
        elif style == "Retro Wave":
            color = [1, 0, 1]  # Magenta
        elif style == "Neon Glow":
            color = [0.5, 1, 0]  # Lime
        else:
            color = [1, 1, 0]  # Yellow
            
        # Animated elements
        frame[300:420, x-20:x+20] = color
        frame[y-50:y+50, 600:680] = color
        
        clips.append(ImageClip(frame).set_duration(0.04))
    
    video = concatenate_videoclips(clips)
    video = video.set_audio(audio)
    
    output_path = os.path.join(tempfile.gettempdir(), "music_video.mp4")
    video.write_videofile(output_path, fps=24)
    return output_path

with gr.Blocks(theme=gr.themes.Soft(), css="footer {visibility: hidden}") as demo:
    gr.Markdown("""# 🎶 AI Music Video Generator 
                *Transform your audio into visual experiences*""")
    
    with gr.Row():
        with gr.Column(scale=1):
            gr.Image("banner.png", show_label=False)
            audio_input = gr.Audio(label="Upload MP3/WAV", type="filepath")
            style_select = gr.Dropdown(
                choices=["Cyberpunk", "Retro Wave", "Neon Glow", "Nature", "Abstract"],
                label="Visual Style",
                value="Cyberpunk"
            )
            duration_slider = gr.Slider(10, 300, value=60, label="Duration (seconds)")
            intensity_slider = gr.Slider(0.5, 2.0, value=1.0, label="Effect Intensity")
            generate_btn = gr.Button("Generate Video 🎬", variant="primary")

        with gr.Column(scale=2):
            video_output = gr.Video(label="Your Music Video", interactive=False)
            gr.Markdown("Share your creation: [Twitter] [Facebook] [Instagram]")

    generate_btn.click(
        fn=generate_music_video,
        inputs=[audio_input, style_select, duration_slider, intensity_slider],
        outputs=[video_output]
    )

if __name__ == "__main__":
    demo.launch()