bluestarburst
commited on
Commit
•
f45086c
1
Parent(s):
0f38a31
Upload folder using huggingface_hub
Browse files- handler.py +16 -8
handler.py
CHANGED
@@ -5,6 +5,7 @@ from transformers import CLIPTextModel, CLIPTokenizer
|
|
5 |
from omegaconf import OmegaConf
|
6 |
from huggingface_hub import hf_hub_download
|
7 |
|
|
|
8 |
|
9 |
from diffusers.utils.import_utils import is_xformers_available
|
10 |
from typing import Any
|
@@ -20,8 +21,8 @@ from animatediff.utils.util import load_weights
|
|
20 |
class EndpointHandler():
|
21 |
def __init__(self, model_path: str = "bluestarburst/AnimateDiff-SceneFusion"):
|
22 |
|
23 |
-
inference_config_path = "configs/inference-v3.yaml"
|
24 |
-
hf_hub_download(repo_id="bluestarburst/AnimateDiff-SceneFusion", filename="configs/inference/inference-v3.yaml"
|
25 |
|
26 |
inference_config = OmegaConf.load(inference_config_path)
|
27 |
|
@@ -30,21 +31,28 @@ class EndpointHandler():
|
|
30 |
### >>> create validation pipeline >>> ###
|
31 |
tokenizer = CLIPTokenizer.from_pretrained(model_path, subfolder="models/StableDiffusion/tokenizer")
|
32 |
text_encoder = CLIPTextModel.from_pretrained(model_path, subfolder="models/StableDiffusion/text_encoder")
|
33 |
-
vae = AutoencoderKL.from_pretrained(model_path, subfolder="models/StableDiffusion/vae")
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
if is_xformers_available(): unet.enable_xformers_memory_efficient_attention()
|
37 |
else: assert False
|
38 |
|
39 |
self.pipeline = AnimationPipeline(
|
40 |
vae=vae, text_encoder=text_encoder, tokenizer=tokenizer, unet=unet,
|
41 |
-
scheduler=DDIMScheduler(**OmegaConf.to_container(inference_config
|
42 |
).to("cuda")
|
43 |
|
44 |
# huggingface download motion module from bluestarburst/AnimateDiff-SceneFusion/models/Motion_Module/mm_sd_v15.ckpt
|
45 |
|
46 |
-
motion_module = "models/
|
47 |
-
hf_hub_download(repo_id="bluestarburst/AnimateDiff-SceneFusion", filename="models/Motion_Module/mm_sd_v15.ckpt"
|
48 |
|
49 |
|
50 |
self.pipeline = load_weights(
|
@@ -97,4 +105,4 @@ class EndpointHandler():
|
|
97 |
# This function will be called during inference time.
|
98 |
|
99 |
|
100 |
-
|
|
|
5 |
from omegaconf import OmegaConf
|
6 |
from huggingface_hub import hf_hub_download
|
7 |
|
8 |
+
import os
|
9 |
|
10 |
from diffusers.utils.import_utils import is_xformers_available
|
11 |
from typing import Any
|
|
|
21 |
class EndpointHandler():
|
22 |
def __init__(self, model_path: str = "bluestarburst/AnimateDiff-SceneFusion"):
|
23 |
|
24 |
+
inference_config_path = "configs/inference/inference-v3.yaml"
|
25 |
+
hf_hub_download(repo_id="bluestarburst/AnimateDiff-SceneFusion", filename="configs/inference/inference-v3.yaml")
|
26 |
|
27 |
inference_config = OmegaConf.load(inference_config_path)
|
28 |
|
|
|
31 |
### >>> create validation pipeline >>> ###
|
32 |
tokenizer = CLIPTokenizer.from_pretrained(model_path, subfolder="models/StableDiffusion/tokenizer")
|
33 |
text_encoder = CLIPTextModel.from_pretrained(model_path, subfolder="models/StableDiffusion/text_encoder")
|
34 |
+
vae = AutoencoderKL.from_pretrained(model_path, subfolder="models/StableDiffusion/vae")
|
35 |
+
|
36 |
+
if not os.path.isfile("models/StableDiffusion/unet/diffusion_pytorch_model.bin"):
|
37 |
+
hf_hub_download(repo_id="bluestarburst/AnimateDiff-SceneFusion", filename="models/StableDiffusion/unet/config.json")
|
38 |
+
hf_hub_download(repo_id="bluestarburst/AnimateDiff-SceneFusion", filename="models/StableDiffusion/unet/diffusion_pytorch_model.bin")
|
39 |
+
|
40 |
+
unet_model_path = "models/StableDiffusion/unet"
|
41 |
+
|
42 |
+
unet = UNet3DConditionModel.from_pretrained_2d(pretrained_model_path=unet_model_path, unet_additional_kwargs=OmegaConf.to_container(inference_config.unet_additional_kwargs))
|
43 |
|
44 |
if is_xformers_available(): unet.enable_xformers_memory_efficient_attention()
|
45 |
else: assert False
|
46 |
|
47 |
self.pipeline = AnimationPipeline(
|
48 |
vae=vae, text_encoder=text_encoder, tokenizer=tokenizer, unet=unet,
|
49 |
+
scheduler=DDIMScheduler(**OmegaConf.to_container(inference_config.noise_scheduler_kwargs.DDIMScheduler))
|
50 |
).to("cuda")
|
51 |
|
52 |
# huggingface download motion module from bluestarburst/AnimateDiff-SceneFusion/models/Motion_Module/mm_sd_v15.ckpt
|
53 |
|
54 |
+
motion_module = "models/MotionModule/mm_sd_v15.ckpt"
|
55 |
+
hf_hub_download(repo_id="bluestarburst/AnimateDiff-SceneFusion", filename="models/Motion_Module/mm_sd_v15.ckpt")
|
56 |
|
57 |
|
58 |
self.pipeline = load_weights(
|
|
|
105 |
# This function will be called during inference time.
|
106 |
|
107 |
|
108 |
+
new_handler = EndpointHandler()
|