From 08130f179c032e98c91e26aa9cab746fbd778a1a Mon Sep 17 00:00:00 2001 From: samizdat Date: Tue, 10 Jun 2025 06:04:55 -0400 Subject: [PATCH] Fix imports to use NODE_CLASS_MAPPINGS from comfyui_controlnet_aux MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Import preprocessor classes from the dynamically loaded NODE_CLASS_MAPPINGS dictionary rather than trying to import directly from module paths. This matches how comfyui_controlnet_aux actually exports its classes. Verified correct node names: - DepthAnythingV2Preprocessor ✓ - DWPreprocessor ✓ - CannyEdgePreprocessor ✓ - OpenposePreprocessor ✓ - MiDaS-DepthMapPreprocessor ✓ --- nodes.py | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/nodes.py b/nodes.py index b405320..624fa00 100644 --- a/nodes.py +++ b/nodes.py @@ -65,7 +65,8 @@ class MultiGPUPreprocessorWrapper: # DepthAnything V2 Wrapper try: - from comfyui_controlnet_aux import DepthAnythingV2Preprocessor + from comfyui_controlnet_aux import NODE_CLASS_MAPPINGS as AUX_NODE_MAPPINGS + DepthAnythingV2Preprocessor = AUX_NODE_MAPPINGS["DepthAnythingV2Preprocessor"] class DepthAnythingV2Wrapper(MultiGPUPreprocessorWrapper): def __init__(self): @@ -80,14 +81,16 @@ try: logger.info("DepthAnythingV2Wrapper loaded successfully") -except ImportError as e: +except (ImportError, KeyError) as e: logger.warning(f"DepthAnythingV2Preprocessor not available: {e}") DepthAnythingV2Wrapper = None # DWPose Wrapper try: - from comfyui_controlnet_aux import DWPreprocessor + if 'AUX_NODE_MAPPINGS' not in locals(): + from comfyui_controlnet_aux import NODE_CLASS_MAPPINGS as AUX_NODE_MAPPINGS + DWPreprocessor = AUX_NODE_MAPPINGS["DWPreprocessor"] class DWPreprocessorWrapper(MultiGPUPreprocessorWrapper): def __init__(self): @@ -102,14 +105,16 @@ try: logger.info("DWPreprocessorWrapper loaded successfully") -except ImportError as e: +except (ImportError, KeyError) as e: logger.warning(f"DWPreprocessor not available: {e}") DWPreprocessorWrapper = None # Canny Edge Wrapper try: - from comfyui_controlnet_aux import CannyEdgePreprocessor + if 'AUX_NODE_MAPPINGS' not in locals(): + from comfyui_controlnet_aux import NODE_CLASS_MAPPINGS as AUX_NODE_MAPPINGS + CannyEdgePreprocessor = AUX_NODE_MAPPINGS["CannyEdgePreprocessor"] class CannyEdgePreprocessorWrapper(MultiGPUPreprocessorWrapper): def __init__(self): @@ -124,14 +129,16 @@ try: logger.info("CannyEdgePreprocessorWrapper loaded successfully") -except ImportError as e: +except (ImportError, KeyError) as e: logger.warning(f"CannyEdgePreprocessor not available: {e}") CannyEdgePreprocessorWrapper = None # OpenPose Wrapper try: - from comfyui_controlnet_aux import OpenposePreprocessor + if 'AUX_NODE_MAPPINGS' not in locals(): + from comfyui_controlnet_aux import NODE_CLASS_MAPPINGS as AUX_NODE_MAPPINGS + OpenposePreprocessor = AUX_NODE_MAPPINGS["OpenposePreprocessor"] class OpenposePreprocessorWrapper(MultiGPUPreprocessorWrapper): def __init__(self): @@ -146,14 +153,16 @@ try: logger.info("OpenposePreprocessorWrapper loaded successfully") -except ImportError as e: +except (ImportError, KeyError) as e: logger.warning(f"OpenposePreprocessor not available: {e}") OpenposePreprocessorWrapper = None # Midas Depth Map Wrapper try: - from comfyui_controlnet_aux import MidasDepthMapPreprocessor + if 'AUX_NODE_MAPPINGS' not in locals(): + from comfyui_controlnet_aux import NODE_CLASS_MAPPINGS as AUX_NODE_MAPPINGS + MidasDepthMapPreprocessor = AUX_NODE_MAPPINGS["MiDaS-DepthMapPreprocessor"] class MidasDepthMapWrapper(MultiGPUPreprocessorWrapper): def __init__(self): @@ -168,7 +177,7 @@ try: logger.info("MidasDepthMapWrapper loaded successfully") -except ImportError as e: +except (ImportError, KeyError) as e: logger.warning(f"MidasDepthMapPreprocessor not available: {e}") MidasDepthMapWrapper = None