|
18 | 18 | import comfy.sd
|
19 | 19 | import comfy.utils
|
20 | 20 |
|
| 21 | +import comfy_extras.clip_vision |
| 22 | + |
21 | 23 | import model_management
|
22 | 24 | import importlib
|
23 | 25 |
|
@@ -370,6 +372,89 @@ def load_clip(self, clip_name):
|
370 | 372 | clip = comfy.sd.load_clip(ckpt_path=clip_path, embedding_directory=CheckpointLoader.embedding_directory)
|
371 | 373 | return (clip,)
|
372 | 374 |
|
| 375 | +class CLIPVisionLoader: |
| 376 | + models_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "models") |
| 377 | + clip_dir = os.path.join(models_dir, "clip_vision") |
| 378 | + @classmethod |
| 379 | + def INPUT_TYPES(s): |
| 380 | + return {"required": { "clip_name": (filter_files_extensions(recursive_search(s.clip_dir), supported_pt_extensions), ), |
| 381 | + }} |
| 382 | + RETURN_TYPES = ("CLIP_VISION",) |
| 383 | + FUNCTION = "load_clip" |
| 384 | + |
| 385 | + CATEGORY = "loaders" |
| 386 | + |
| 387 | + def load_clip(self, clip_name): |
| 388 | + clip_path = os.path.join(self.clip_dir, clip_name) |
| 389 | + clip_vision = comfy_extras.clip_vision.load(clip_path) |
| 390 | + return (clip_vision,) |
| 391 | + |
| 392 | +class CLIPVisionEncode: |
| 393 | + @classmethod |
| 394 | + def INPUT_TYPES(s): |
| 395 | + return {"required": { "clip_vision": ("CLIP_VISION",), |
| 396 | + "image": ("IMAGE",) |
| 397 | + }} |
| 398 | + RETURN_TYPES = ("CLIP_VISION_EMBED",) |
| 399 | + FUNCTION = "encode" |
| 400 | + |
| 401 | + CATEGORY = "conditioning" |
| 402 | + |
| 403 | + def encode(self, clip_vision, image): |
| 404 | + output = clip_vision.encode_image(image) |
| 405 | + return (output,) |
| 406 | + |
| 407 | +class StyleModelLoader: |
| 408 | + models_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "models") |
| 409 | + style_model_dir = os.path.join(models_dir, "style_models") |
| 410 | + @classmethod |
| 411 | + def INPUT_TYPES(s): |
| 412 | + return {"required": { "style_model_name": (filter_files_extensions(recursive_search(s.style_model_dir), supported_pt_extensions), )}} |
| 413 | + |
| 414 | + RETURN_TYPES = ("STYLE_MODEL",) |
| 415 | + FUNCTION = "load_style_model" |
| 416 | + |
| 417 | + CATEGORY = "loaders" |
| 418 | + |
| 419 | + def load_style_model(self, style_model_name): |
| 420 | + style_model_path = os.path.join(self.style_model_dir, style_model_name) |
| 421 | + style_model = comfy.sd.load_style_model(style_model_path) |
| 422 | + return (style_model,) |
| 423 | + |
| 424 | + |
| 425 | +class StyleModelApply: |
| 426 | + @classmethod |
| 427 | + def INPUT_TYPES(s): |
| 428 | + return {"required": {"clip_vision_embed": ("CLIP_VISION_EMBED", ), |
| 429 | + "style_model": ("STYLE_MODEL", ) |
| 430 | + }} |
| 431 | + RETURN_TYPES = ("CONDITIONING",) |
| 432 | + FUNCTION = "apply_stylemodel" |
| 433 | + |
| 434 | + CATEGORY = "conditioning" |
| 435 | + |
| 436 | + def apply_stylemodel(self, clip_vision_embed, style_model): |
| 437 | + c = style_model.get_cond(clip_vision_embed) |
| 438 | + return ([[c, {}]], ) |
| 439 | + |
| 440 | + |
| 441 | +class ConditioningAppend: |
| 442 | + @classmethod |
| 443 | + def INPUT_TYPES(s): |
| 444 | + return {"required": {"conditioning_to": ("CONDITIONING", ), "conditioning_from": ("CONDITIONING", )}} |
| 445 | + RETURN_TYPES = ("CONDITIONING",) |
| 446 | + FUNCTION = "append" |
| 447 | + |
| 448 | + CATEGORY = "conditioning" |
| 449 | + |
| 450 | + def append(self, conditioning_to, conditioning_from): |
| 451 | + c = [] |
| 452 | + to_append = conditioning_from[0][0] |
| 453 | + for t in conditioning_to: |
| 454 | + n = [torch.cat((t[0],to_append), dim=1), t[1].copy()] |
| 455 | + c.append(n) |
| 456 | + return (c, ) |
| 457 | + |
373 | 458 | class EmptyLatentImage:
|
374 | 459 | def __init__(self, device="cpu"):
|
375 | 460 | self.device = device
|
@@ -866,6 +951,11 @@ def invert(self, image):
|
866 | 951 | "LatentCrop": LatentCrop,
|
867 | 952 | "LoraLoader": LoraLoader,
|
868 | 953 | "CLIPLoader": CLIPLoader,
|
| 954 | + "StyleModelLoader": StyleModelLoader, |
| 955 | + "CLIPVisionLoader": CLIPVisionLoader, |
| 956 | + "CLIPVisionEncode": CLIPVisionEncode, |
| 957 | + "StyleModelApply":StyleModelApply, |
| 958 | + "ConditioningAppend":ConditioningAppend, |
869 | 959 | "ControlNetApply": ControlNetApply,
|
870 | 960 | "ControlNetLoader": ControlNetLoader,
|
871 | 961 | "DiffControlNetLoader": DiffControlNetLoader,
|
|
0 commit comments