Spaces:
Running on Zero
Running on Zero
File size: 1,171 Bytes
d6cb15d e0e1031 b626c78 1f5e09d b626c78 1f5e09d b626c78 1f5e09d b626c78 d6cb15d e0e1031 b626c78 1f5e09d b626c78 1f5e09d b901516 b626c78 1f5e09d b626c78 1f5e09d b626c78 d6cb15d e0e1031 b626c78 e0e1031 b626c78 1f5e09d b626c78 e0e1031 b626c78 e0e1031 d6cb15d | 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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | import gradio as gr
import spaces
import torch
import tempfile
from diffusers import LTXImageToVideoPipeline
from diffusers.utils import export_to_video
pipe = LTXImageToVideoPipeline.from_pretrained(
"Lightricks/LTX-Video",
torch_dtype=torch.bfloat16
)
pipe.to("cuda")
@spaces.GPU
def generate_video(image, prompt):
if image is None:
raise gr.Error("Please upload an image.")
if not prompt.strip():
raise gr.Error("Please describe the movement.")
video = pipe(
image=image,
prompt=prompt,
width=704,
height=480,
num_frames=49,
num_inference_steps=20,
).frames[0]
output_file = tempfile.NamedTemporaryFile(
suffix=".mp4",
delete=False
).name
export_to_video(video, output_file, fps=24)
return output_file
demo = gr.Interface(
fn=generate_video,
inputs=[
gr.Image(type="pil", label="Real Image"),
gr.Textbox(
label="Motion Prompt",
placeholder="Describe realistic movement..."
),
],
outputs=gr.Video(label="Generated Video"),
title="Real Image → Video",
)
demo.launch() |