import gradio as gr from moviepy.editor import ImageClip, concatenate_videoclips, AudioFileClip import tempfile def merge_images_audio(image_file, audio_file, video_size=(1080, 1920)): image_duration = 3.5 # Duration for each image in seconds video_duration = image_duration def centered_image_clip(img_path, size): img_clip = ImageClip(img_path.name).resize(video_size) # Resize image to video_size return img_clip.set_position("center").set_duration(image_duration) image_clip = centered_image_clip(image_file, video_size) final_video = concatenate_videoclips([image_clip]) audio_clip = AudioFileClip(audio_file.name).subclip(0, video_duration) # Trim or loop audio to match video duration final_video = final_video.set_audio(audio_clip) output_filename = tempfile.mktemp(suffix=".mp4") final_video.write_videofile(output_filename, codec='libx264', fps=24) return "Video created successfully!", output_filename iface = gr.Interface( fn=merge_images_audio, inputs=[ gr.inputs.File(label="Image File"), # Single file selection gr.inputs.File(label="Audio File") ], outputs=[ "text", gr.outputs.File(label="Download Video") # File output without 'type' ] ) iface.launch()