1414from LightGlue .lightglue import LightGlue , SuperPoint
1515from LightGlue .lightglue .utils import rbd
1616
17- from models_diffusers .unet_spatio_temporal_condition import UNetSpatioTemporalConditionModel
17+ from models_diffusers .unet_spatio_temporal_condition import (
18+ UNetSpatioTemporalConditionModel ,
19+ )
1820from models_diffusers .controlnet_svd import ControlNetSVDModel
1921
20- from cotracker .predictor import CoTrackerPredictor , sample_trajectories_with_ref
22+ try :
23+ from cotracker .predictor import CoTrackerPredictor , sample_trajectories_with_ref
24+ except :
25+ pass
2126
2227from lineart_extractor .canny import CannyDetector
2328from lineart_extractor .hed import HEDdetector
5055 folder_paths .supported_pt_extensions ,
5156)
5257
58+
5359class AniDocLoader :
5460 @classmethod
5561 def INPUT_TYPES (cls ):
@@ -80,17 +86,20 @@ def load_anidoc(
8086 if self .pipeline is None :
8187 pbar = ProgressBar (5 )
8288
83- if not os .path .exists (anidoc_path ):
84- log .info (f"Downloading AniDoc model to: { anidoc_path } " )
89+ pbar .update (1 )
90+
91+ log .info (f"Loading model from: { anidoc_path } " )
92+ log .info ("Missing models will be downloaded" )
93+
94+ try :
8595 snapshot_download (
8696 repo_id = "Yhmeng1106/anidoc" ,
97+ ignore_patterns = ["*.md" ],
8798 local_dir = DIFFUSERS_DIR ,
8899 local_dir_use_symlinks = False ,
89100 )
90-
91- pbar .update (1 )
92-
93- log .info (f"Loading model from: { anidoc_path } " )
101+ except :
102+ log .info ("Couldn't download models" )
94103
95104 unet = UNetSpatioTemporalConditionModel .from_pretrained (
96105 anidoc_path ,
@@ -111,23 +120,25 @@ def load_anidoc(
111120 pbar .update (1 )
112121
113122 if XFORMERS_IS_AVAILABLE :
114- log .info (f "Enabling XFormers" )
123+ log .info ("Enabling XFormers" )
115124 unet .enable_xformers_memory_efficient_attention ()
116125
117- if not os .path .exists (svd_img2vid_path ):
118- log .info (f"Downloading stable diffusion video img2vid to: { svd_img2vid_path } " )
126+ log .info (f"Loading model from: { svd_img2vid_path } " )
127+ log .info ("Missing models will be downloaded" )
128+
129+ try :
119130 snapshot_download (
120131 repo_id = "vdo/stable-video-diffusion-img2vid-xt-1-1" ,
121- allow_patterns = [f "*.json" , "*fp16*" ],
132+ allow_patterns = ["*.json" , "*fp16*" ],
122133 ignore_patterns = ["*unet*" ],
123134 local_dir = svd_img2vid_path ,
124135 local_dir_use_symlinks = False ,
125136 )
137+ except :
138+ log .info ("Couldn't download models" )
126139
127140 pbar .update (1 )
128141
129- log .info (f"Loading model from: { svd_img2vid_path } " )
130-
131142 pipeline = AniDocPipeline .from_pretrained (
132143 svd_img2vid_path ,
133144 unet = unet ,
@@ -190,6 +201,11 @@ def load_tracker(
190201 device = "cuda" ,
191202 dtype = torch .float32 ,
192203 ):
204+ try :
205+ import cotracker
206+ except :
207+ raise ImportError ("Couldn't import cotracker module. Please install it to use this node" )
208+
193209 if tracking :
194210 if self .tracker is None or self .tracker_shift_grid != tracker_shift_grid :
195211 cotracker_model_path = folder_paths .get_full_path (
@@ -278,7 +294,7 @@ def invert_images(self, image):
278294 return cv2 .bitwise_not (image )
279295 else :
280296 return 255 - image
281-
297+
282298 def get_controlnet_images (
283299 self ,
284300 input_images ,
@@ -295,7 +311,7 @@ def get_controlnet_images(
295311
296312 pbar .update (1 )
297313
298- log .info (f "Processing images with lineart detector" )
314+ log .info ("Processing images with lineart detector" )
299315
300316 controlnet_images = []
301317
@@ -307,7 +323,7 @@ def get_controlnet_images(
307323 sketch = detector (sketch , 100 , 200 )
308324 else :
309325 sketch = detector (sketch )
310-
326+
311327 if lineart_detector in ["canny" , "hed" ]:
312328 sketch = self .invert_images (sketch )
313329
@@ -689,7 +705,9 @@ def sample(
689705 noise_aug_strength = noise_aug ,
690706 decode_chunk_size = decode_chunk_size ,
691707 generator = generator ,
692- callback_on_step_end = lambda * args , ** kwargs : (pbar .update (1 ), kwargs )[- 1 ],
708+ callback_on_step_end = lambda * args , ** kwargs : (pbar .update (1 ), kwargs )[
709+ - 1
710+ ],
693711 ).frames [0 ]
694712
695713 tensor_frames = [T .ToTensor ()(img ) for img in video_frames ]
0 commit comments