File size: 1,567 Bytes
4100a68
28c3203
4100a68
 
 
 
 
 
 
 
 
 
cd71a0d
 
c0f38a5
cd71a0d
 
 
 
 
4100a68
 
 
 
 
 
 
 
 
 
cd71a0d
4100a68
 
 
cd71a0d
4100a68
 
cd71a0d
 
 
 
 
 
4100a68
 
 
 
 
 
cd71a0d
 
4100a68
 
cd71a0d
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
model based on  https://civitai.com/models/108124/realisticmechv1 

converted to use it with animatediff with diffusers on hugging face

A code sample :

import torch
from diffusers import AnimateDiffPipeline, DDIMScheduler, MotionAdapter
from diffusers.utils import export_to_gif

# Load the motion adapter
adapter = MotionAdapter.from_pretrained("guoyww/animatediff-motion-adapter-v1-5-2", torch_dtype=torch.float16)

# Load SD 1.5 based finetuned model
model_id = "zecloud/mechas"
pipe = AnimateDiffPipeline.from_pretrained(
    model_id,
    motion_adapter=adapter,
    torch_dtype=torch.float16
)
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()

# Define the input prompts and generate the output
output = pipe(
    prompt=(
        "half body portrait of man smiling with a mysterious gaze, mecha, science_fiction, city, realistic,mecha, "
        "a futuristic eiffel tower in the background "
    ),
    negative_prompt=(
        "(worst quality, low quality:1.4), (bad_prompt_version2:0.8), EasyNegative, badhandv4, text, name, letters, "
        "watermark, two tower"
    ),
    num_frames=16,
    guidance_scale=7.0,
    num_inference_steps=32,
    generator=torch.Generator("cpu").manual_seed(42),
)

# Extract frames and export to GIF
frames = output.frames[0]
export_to_gif(frames, "animation.gif")