Created
December 8, 2025 21:11
-
-
Save spinningcat/e21ffe141426ec89d0381c8cd50baa16 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import torch, os | |
| from diffusers import StableDiffusionPipeline | |
| from moviepy.editor import ImageSequenceClip | |
| pipe = StableDiffusionPipeline.from_pretrained( | |
| "runwayml/stable-diffusion-v1-5", | |
| torch_dtype=torch.float16, | |
| ).to("cuda") | |
| prompt = r"The people in this photo were in a hurry to cross the street, and the traffic light had just turned green. However, something in my brain signaled me to take action and capture them in their natural state." | |
| fps = 30 | |
| duration = 5 # seconds | |
| frames = fps * duration | |
| width, height = 640, 360 | |
| os.makedirs("frames", exist_ok=True) | |
| for i in range(frames): | |
| seed = 42 + i | |
| torch.manual_seed(seed) | |
| image = pipe(prompt).images[0] | |
| image = image.resize((width, height)) | |
| image.save(f"frames/frame_{i:04d}.png") | |
| print(f"Generated frame {i+1}/{frames}") | |
| clip = ImageSequenceClip("frames", fps=fps) | |
| clip.write_videofile("/content/video.mp4", codec="libx264", audio=False) | |
| print("Video created video.mp4") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment