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 | |
| # enable memory savings | |
| pipe.enable_vae_slicing() | |
| pipe.enable_model_cpu_offload() | |
| def generate(prompt): | |
| pipe.to(device) | |
| output = pipe( | |
| prompt=prompt, | |
| negative_prompt="bad quality, worse quality", | |
| num_frames=16, | |
| guidance_scale=7.5, | |
| num_inference_steps=4, | |
| ) | |
| 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, | |
| inputs=gr.Textbox(label="Enter your prompt"), | |
| outputs=gr.Video(label="Generated Video"), | |
| ) | |
| iface.launch() |