Spaces:
Build error
Build error
File size: 1,736 Bytes
0b8d6b0 4ef7343 5cac326 d47b840 0b8d6b0 4ef7343 fe4e57e 9bdf0ae 86f0707 d8769ff 5cac326 4ef7343 5cac326 4ef7343 9bdf0ae d8769ff 5cac326 d8769ff 0301faf d8769ff 9bdf0ae 4ef7343 5cac326 |
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 38 39 40 41 42 43 |
import gradio as gr
from diffusers import StableVideoDiffusionPipeline, EulerDiscreteScheduler
import torch
from PIL import Image
import spaces
# Load the Stable Video Diffusion model
model_id = "stabilityai/stable-video-diffusion-img2vid-xt"
pipe = StableVideoDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16, revision="main")
pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config)
pipe.to("cuda")
@spaces.GPU
def generate_video(image, prompt, num_frames=25, height=576, width=1024):
# Convert the image to a format suitable for the pipeline
image = Image.open(image)
# Generate the video
video_frames = pipe(prompt=prompt, init_image=image, num_frames=num_frames, height=height, width=width).frames
return video_frames
# Create the Gradio interface
with gr.Blocks() as demo:
gr.Markdown("## Image to Video with Stable Diffusion XT")
with gr.Row():
with gr.Column():
image_input = gr.Image(type="filepath", label="Upload Image")
prompt_input = gr.Textbox(lines=2, placeholder="Enter prompt...", label="Prompt")
num_frames_input = gr.Slider(1, 50, step=1, value=25, label="Number of Frames")
height_input = gr.Number(label="Resolution Height", value=576)
width_input = gr.Number(label="Resolution Width", value=1024)
run_button = gr.Button("Generate Video")
with gr.Column():
video_output = gr.Video(label="Generated Video")
run_button.click(
generate_video,
inputs=[image_input, prompt_input, num_frames_input, height_input, width_input],
outputs=video_output
)
# Launch the interface
if __name__ == "__main__":
demo.launch() |