Spaces:
Paused
Paused
test gradio
Browse files
app.py
CHANGED
@@ -3,8 +3,8 @@ from huggingface_hub import login
|
|
3 |
import os
|
4 |
import spaces,tempfile
|
5 |
import torch
|
6 |
-
from diffusers import
|
7 |
-
from diffusers.models import AutoencoderKL, MotionAdapter,
|
8 |
from diffusers.schedulers import DPMSolverMultistepScheduler
|
9 |
from diffusers.utils import export_to_gif, load_image
|
10 |
from diffusers import AutoPipelineForText2Image
|
@@ -58,10 +58,8 @@ lora_adapter_id = "guoyww/animatediff-motion-lora-v1-5-3"
|
|
58 |
vae_id = "stabilityai/sd-vae-ft-mse"
|
59 |
device = "cuda"
|
60 |
|
61 |
-
controlnet = ControlNetModel.from_single_file("control_v11f1p_sd15_depth.pth", torch_dtype=torch.float16)
|
62 |
-
|
63 |
motion_adapter = MotionAdapter.from_pretrained(motion_adapter_id, torch_dtype=torch.float16).to(device)
|
64 |
-
controlnet =
|
65 |
vae = AutoencoderKL.from_pretrained(vae_id, torch_dtype=torch.float16).to(device)
|
66 |
scheduler = DPMSolverMultistepScheduler.from_pretrained(
|
67 |
model_id,
|
@@ -70,7 +68,7 @@ scheduler = DPMSolverMultistepScheduler.from_pretrained(
|
|
70 |
algorithm_type="dpmsolver++",
|
71 |
use_karras_sigmas=True,
|
72 |
)
|
73 |
-
gif_pipe =
|
74 |
model_id,
|
75 |
motion_adapter=motion_adapter,
|
76 |
controlnet=controlnet,
|
@@ -79,7 +77,6 @@ gif_pipe = AnimateDiffControlNetPipeline.from_pretrained(
|
|
79 |
torch_dtype=torch.float16,
|
80 |
).to(device)
|
81 |
gif_pipe.load_lora_weights(lora_adapter_id, adapter_name="motion_lora")
|
82 |
-
gif_pipe.enable_free_noise(context_length=16, context_stride=4)
|
83 |
|
84 |
|
85 |
|
@@ -152,21 +149,12 @@ This way, each frame represents a distinct scene, and there’s no redundancy be
|
|
152 |
controlnet_frame_indices.append(frame['frame_index'])
|
153 |
long_prompt[frame['frame_index']] = frame['description']
|
154 |
|
155 |
-
full_images = []
|
156 |
-
last_image = conditioning_frames[0]
|
157 |
-
sparse_index_pointer = 0
|
158 |
-
|
159 |
-
for frame_index in range(max(controlnet_frame_indices)):
|
160 |
-
if sparse_index_pointer < len(controlnet_frame_indices) and frame_index == controlnet_frame_indices[sparse_index_pointer]:
|
161 |
-
last_image = controlnet_frame_indices[sparse_index_pointer]
|
162 |
-
sparse_index_pointer += 1
|
163 |
-
full_images.append(last_image)
|
164 |
-
|
165 |
video = gif_pipe(
|
166 |
prompt=long_prompt,
|
167 |
negative_prompt="low quality, worst quality",
|
168 |
num_inference_steps=25,
|
169 |
-
conditioning_frames=
|
|
|
170 |
controlnet_conditioning_scale=float(controlnet_conditioning_scale),
|
171 |
).frames[0]
|
172 |
export_to_gif(video, "output.gif")
|
|
|
3 |
import os
|
4 |
import spaces,tempfile
|
5 |
import torch
|
6 |
+
from diffusers import AnimateDiffSparseControlNetPipeline
|
7 |
+
from diffusers.models import AutoencoderKL, MotionAdapter, SparseControlNetModel
|
8 |
from diffusers.schedulers import DPMSolverMultistepScheduler
|
9 |
from diffusers.utils import export_to_gif, load_image
|
10 |
from diffusers import AutoPipelineForText2Image
|
|
|
58 |
vae_id = "stabilityai/sd-vae-ft-mse"
|
59 |
device = "cuda"
|
60 |
|
|
|
|
|
61 |
motion_adapter = MotionAdapter.from_pretrained(motion_adapter_id, torch_dtype=torch.float16).to(device)
|
62 |
+
controlnet = SparseControlNetModel.from_pretrained(controlnet_id, torch_dtype=torch.float16).to(device)
|
63 |
vae = AutoencoderKL.from_pretrained(vae_id, torch_dtype=torch.float16).to(device)
|
64 |
scheduler = DPMSolverMultistepScheduler.from_pretrained(
|
65 |
model_id,
|
|
|
68 |
algorithm_type="dpmsolver++",
|
69 |
use_karras_sigmas=True,
|
70 |
)
|
71 |
+
gif_pipe = AnimateDiffSparseControlNetPipeline.from_pretrained(
|
72 |
model_id,
|
73 |
motion_adapter=motion_adapter,
|
74 |
controlnet=controlnet,
|
|
|
77 |
torch_dtype=torch.float16,
|
78 |
).to(device)
|
79 |
gif_pipe.load_lora_weights(lora_adapter_id, adapter_name="motion_lora")
|
|
|
80 |
|
81 |
|
82 |
|
|
|
149 |
controlnet_frame_indices.append(frame['frame_index'])
|
150 |
long_prompt[frame['frame_index']] = frame['description']
|
151 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
152 |
video = gif_pipe(
|
153 |
prompt=long_prompt,
|
154 |
negative_prompt="low quality, worst quality",
|
155 |
num_inference_steps=25,
|
156 |
+
conditioning_frames=conditioning_frames,
|
157 |
+
controlnet_frame_indices=controlnet_frame_indices,
|
158 |
controlnet_conditioning_scale=float(controlnet_conditioning_scale),
|
159 |
).frames[0]
|
160 |
export_to_gif(video, "output.gif")
|