From 33c31127b58ab216f53382ea72ad255809106188 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E9=9B=AA=E5=B3=B0?= Date: Wed, 13 Mar 2024 18:54:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=8A=A0=E6=A8=A1=E5=9D=97=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __init__.py | 19 +++++++++++-------- easyapi/DetectNode.py | 2 +- easyapi/ImageNode.py | 2 +- easyapi/SamNode.py | 2 +- easyapi/UtilNode.py | 2 +- easyapi/__init__.py | 0 6 files changed, 15 insertions(+), 12 deletions(-) create mode 100644 easyapi/__init__.py diff --git a/__init__.py b/__init__.py index e8ff1c4..1e6bb03 100644 --- a/__init__.py +++ b/__init__.py @@ -10,24 +10,27 @@ NODE_CLASS_MAPPINGS = {} NODE_DISPLAY_NAME_MAPPINGS = {} pyPath = os.path.join(extension_folder, 'easyapi') -sys.path.append(extension_folder) +# sys.path.append(extension_folder) logScript.log_wrap() -api.init() +# api.init() def loadCustomNodes(): files = glob.glob(os.path.join(pyPath, "*Node.py"), recursive=True) - for file in files: - name = os.path.splitext(file)[0] - spec = importlib.util.spec_from_file_location(name, file) - module = importlib.util.module_from_spec(spec) - sys.modules[name] = module - spec.loader.exec_module(module) + api_files = glob.glob(os.path.join(pyPath, "api.py"), recursive=True) + find_files = files + api_files + for file in find_files: + file_relative_path = file[len(extension_folder):] + model_name = file_relative_path.replace(os.sep, '.') + model_name = os.path.splitext(model_name)[0] + module = importlib.import_module(model_name, __name__) if hasattr(module, "NODE_CLASS_MAPPINGS") and getattr(module, "NODE_CLASS_MAPPINGS") is not None: NODE_CLASS_MAPPINGS.update(module.NODE_CLASS_MAPPINGS) if hasattr(module, "NODE_DISPLAY_NAME_MAPPINGS") and getattr(module, "NODE_DISPLAY_NAME_MAPPINGS") is not None: NODE_DISPLAY_NAME_MAPPINGS.update(module.NODE_DISPLAY_NAME_MAPPINGS) + if hasattr(module, "init"): + getattr(module, "init")() loadCustomNodes() diff --git a/easyapi/DetectNode.py b/easyapi/DetectNode.py index 1e0ec19..fdf3ac5 100644 --- a/easyapi/DetectNode.py +++ b/easyapi/DetectNode.py @@ -4,7 +4,7 @@ from PIL import Image from json import JSONEncoder, JSONDecoder import numpy as np -from easyapi.util import tensor_to_pil, pil_to_tensor, hex_to_rgba +from .util import tensor_to_pil, pil_to_tensor, hex_to_rgba import folder_paths diff --git a/easyapi/ImageNode.py b/easyapi/ImageNode.py index c6e03c6..39c2988 100644 --- a/easyapi/ImageNode.py +++ b/easyapi/ImageNode.py @@ -9,7 +9,7 @@ from comfy.cli_args import args from PIL.PngImagePlugin import PngInfo import json from json import JSONEncoder, JSONDecoder -from easyapi.util import tensor_to_pil, pil_to_tensor, base64_to_image, image_to_base64, read_image_from_url +from .util import tensor_to_pil, pil_to_tensor, base64_to_image, image_to_base64, read_image_from_url class LoadImageFromURL: diff --git a/easyapi/SamNode.py b/easyapi/SamNode.py index da6ee60..5f873eb 100644 --- a/easyapi/SamNode.py +++ b/easyapi/SamNode.py @@ -2,7 +2,7 @@ from segment_anything import SamAutomaticMaskGenerator import json import numpy as np -from easyapi.util import tensor_to_pil +from .util import tensor_to_pil class SamAutoMaskSEGS: @classmethod diff --git a/easyapi/UtilNode.py b/easyapi/UtilNode.py index 59ec393..9e299b8 100644 --- a/easyapi/UtilNode.py +++ b/easyapi/UtilNode.py @@ -1,4 +1,4 @@ -from easyapi.util import tensor_to_pil, hex_to_rgba +from .util import tensor_to_pil, hex_to_rgba class GetImageBatchSize: diff --git a/easyapi/__init__.py b/easyapi/__init__.py new file mode 100644 index 0000000..e69de29