Spaces:
Running
Running
File size: 726 Bytes
cb78791 d88a4e9 cb78791 a780cef d88a4e9 cb78791 d88a4e9 a780cef d88a4e9 cb78791 d88a4e9 cb78791 d88a4e9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
from diffusers import StableVideoDiffusionPipeline
import torch
from PIL import Image
# Model Load
pipe = StableVideoDiffusionPipeline.from_pretrained(
"stabilityai/stable-video-diffusion-img2vid",
torch_dtype=torch.float16
).to("cuda")
def generate_video(image_path, prompt):
image = Image.open(image_path).convert("RGB") # Load image properly
video = pipe(prompt=prompt, image=image, num_inference_steps=25).frames
video_path = "generated_video.mp4"
video[0].save(video_path) # Save the first generated video
return video_path
# Example Usage
video_file = generate_video("sample_image.jpg", "A beautiful mountain landscape with a sunset")
print(f"Video generated and saved at: {video_file}") |