Spaces:
Runtime error
Runtime error
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 | |
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() |