Spaces:
Runtime error
Runtime error
Create spp_1.py
Browse files
spp_1.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from diffusers import AnimateDiffPipeline, DDIMScheduler, MotionAdapter
|
| 3 |
+
from diffusers.utils import export_to_gif
|
| 4 |
+
|
| 5 |
+
# Load motion adapter
|
| 6 |
+
adapter = MotionAdapter.from_pretrained("guoyww/animatediff-motion-adapter-v1-5-2", torch_dtype=torch.float16)
|
| 7 |
+
|
| 8 |
+
# Load SD 1.5-based model
|
| 9 |
+
model_id = "SG161222/Realistic_Vision_V5.1_noVAE"
|
| 10 |
+
pipe = AnimateDiffPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
|
| 11 |
+
|
| 12 |
+
# Attach motion adapter
|
| 13 |
+
pipe.motion_adapter = adapter
|
| 14 |
+
|
| 15 |
+
# Configure scheduler properly
|
| 16 |
+
pipe.scheduler = DDIMScheduler.from_config(pipe.scheduler.config)
|
| 17 |
+
|
| 18 |
+
# Enable memory-efficient settings
|
| 19 |
+
pipe.enable_xformers_memory_efficient_attention() # Speeds up inference
|
| 20 |
+
pipe.enable_vae_slicing() # Saves VRAM
|
| 21 |
+
pipe.enable_model_cpu_offload() # Offloads to CPU when VRAM is low
|
| 22 |
+
|
| 23 |
+
# Set up inference
|
| 24 |
+
generator = torch.manual_seed(42)
|
| 25 |
+
output = pipe(
|
| 26 |
+
prompt=(
|
| 27 |
+
"masterpiece, best quality, highly detailed, ultradetailed, sunset, "
|
| 28 |
+
"orange sky, warm lighting, fishing boats, ocean waves, seagulls, "
|
| 29 |
+
"rippling water, wharf, silhouette, serene atmosphere, dusk, evening glow, "
|
| 30 |
+
"golden hour, coastal landscape, seaside scenery"
|
| 31 |
+
),
|
| 32 |
+
negative_prompt="low quality, blurry, distorted, deformed, ugly",
|
| 33 |
+
num_frames=16,
|
| 34 |
+
guidance_scale=7.5,
|
| 35 |
+
num_inference_steps=25,
|
| 36 |
+
generator=generator,
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
# Save animation as GIF
|
| 40 |
+
export_to_gif(output.frames[0], "animation.gif")
|