Spaces:
Runtime error
Runtime error
File size: 1,647 Bytes
5bd9da0 f9a5dfd 5bd9da0 f9a5dfd c19b47e 5bd9da0 c19b47e f9a5dfd c19b47e 5bd9da0 |
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 |
import gradio as gr
import torch
from diffusers import AnimateDiffPipeline, DDIMScheduler, MotionAdapter
from diffusers.utils import export_to_gif
from diffusers.utils import export_to_video
import uuid
import spaces
device = "cuda"
adapter = MotionAdapter.from_pretrained("guoyww/animatediff-motion-adapter-v1-5-2", torch_dtype=torch.float16)
model_id = "SG161222/Realistic_Vision_V5.1_noVAE"
pipe = AnimateDiffPipeline.from_pretrained(model_id, motion_adapter=adapter, torch_dtype=torch.float16).to(device)
scheduler = DDIMScheduler.from_pretrained(
model_id,
subfolder="scheduler",
clip_sample=False,
timestep_spacing="linspace",
beta_schedule="linear",
steps_offset=1,
)
pipe.scheduler = scheduler
@spaces.GPU
def generate_video(prompt, guidance_scale, num_inference_steps,num_frames):
pipe.to(device)
output = pipe(
prompt=prompt,
negative_prompt="bad quality, worse quality",
num_frames=num_frames,
guidance_scale=guidance_scale,
num_inference_steps=num_inference_steps,
)
name = str(uuid.uuid4()).replace("-", "")
path = f"/tmp/{name}.mp4"
export_to_video(output.frames[0], path, fps=10)
return path
iface = gr.Interface(
fn=generate_video,
inputs=[
gr.Textbox(label="Enter your prompt"),
gr.Slider(minimum=0.5, maximum=10, value=7.5, label="Guidance Scale"),
gr.Slider(minimum=4, maximum=24, step=4, value=4, label="Inference Steps"),
gr.Slider(minimum=16, maximum=64, step = 1, value = 16, label = "Frames")
],
outputs=gr.Video(label="Generated Video"),
)
iface.launch() |