Spaces:
Runtime error
Runtime error
File size: 1,289 Bytes
7d89612 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
import gradio as gr
import torch
from diffusers import DiffusionPipeline
from PIL import Image
import numpy as np
import io
# ุชุญู
ูู ุงููู
ูุฐุฌ
model_id = "stabilityai/stable-video-diffusion-img2vid"
pipe = DiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16).to("cuda")
def generate_video(image):
# ุชุญููู ุงูุตูุฑุฉ ุฅูู ุชูุณูุฑ
image_tensor = torch.tensor(np.array(image)).float().unsqueeze(0).permute(0, 3, 1, 2).to("cuda") / 255.0
# ุชูููุฏ ุงูููุฏูู
video_frames = pipe(image_tensor, num_frames=25).images # ุงูุชุฑุถูุง 25 ุฅุทุงุฑ ูุนุฏุฏ ุงูุชุฑุงุถู
# ุญูุธ ุงูููุฏูู ุงููุงุชุฌ ุฅูู ู
ูู
video_bytes = io.BytesIO()
video_frames[0].save(video_bytes, format="mp4") # ุงุญูุธ ุงูุฅุทุงุฑ ุงูุฃูู ูููุฏูู ููุฅุดุงุฑุฉ
return video_bytes.getvalue()
# ุฅุนุฏุงุฏ ูุงุฌูุฉ Gradio
interface = gr.Interface(
fn=generate_video,
inputs=gr.Image(type="pil", label="Upload an Image"),
outputs=gr.File(label="Download Video"),
title="Stable Video Diffusion - Image to Video",
description="Upload an image to generate a video using the Stable Video Diffusion model.",
)
# ุชุดุบูู ุงููุงุฌูุฉ
if __name__ == "__main__":
interface.launch()
|