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()