| import gradio as gr |
| import os |
| import cv2 |
| from PIL import Image |
| import tempfile |
|
|
| def images_to_video(image_files, fps): |
| temp_dir = tempfile.mkdtemp() |
| image_paths = [] |
|
|
| |
| for idx, file in enumerate(image_files): |
| img = Image.open(file.name).convert("RGB") |
| img_path = os.path.join(temp_dir, f"img_{idx:03d}.png") |
| img.save(img_path) |
| image_paths.append(img_path) |
|
|
| if not image_paths: |
| return "No images uploaded!" |
|
|
| |
| first_image = cv2.imread(image_paths[0]) |
| height, width, _ = first_image.shape |
|
|
| video_path = os.path.join(temp_dir, "output_video.mp4") |
| fourcc = cv2.VideoWriter_fourcc(*'mp4v') |
| video = cv2.VideoWriter(video_path, fourcc, fps, (width, height)) |
|
|
| for path in image_paths: |
| img = cv2.imread(path) |
| video.write(img) |
|
|
| video.release() |
| return video_path |
|
|
| |
| iface = gr.Interface( |
| fn=images_to_video, |
| inputs=[ |
| gr.File(file_types=["image"], file_count="multiple", label="Upload Images"), |
| gr.Slider(minimum=1, maximum=60, value=10, label="FPS (frames per second)") |
| ], |
| outputs=gr.Video(label="Generated Video"), |
| title="🖼️➡️🎥 Image to Video Converter", |
| description="Upload images and turn them into a video. Because who has time for manual editing?" |
| ) |
|
|
| if __name__ == "__main__": |
| iface.launch() |
|
|