Load custom nodes from mounted bucket
Browse files
app.py
CHANGED
|
@@ -90,11 +90,7 @@ DATA_DIR = Path(os.environ.get("DATA_DIR", DEFAULT_DATA_DIR))
|
|
| 90 |
LOCAL_MODEL_DIR = Path(os.environ.get("LOCAL_MODEL_DIR", "/tmp/models"))
|
| 91 |
COMFYUI_PATH = Path(os.environ.get("COMFYUI_PATH", Path.cwd() / "ComfyUI"))
|
| 92 |
MOUNTED_CUSTOM_NODES_DIR = BUCKET_MOUNT / "custom_nodes"
|
| 93 |
-
CUSTOM_NODES_DIR = (
|
| 94 |
-
MOUNTED_CUSTOM_NODES_DIR
|
| 95 |
-
if MOUNTED_CUSTOM_NODES_DIR.is_dir()
|
| 96 |
-
else Path("/tmp/custom_nodes")
|
| 97 |
-
)
|
| 98 |
OUTPUT_DIR = DATA_DIR / "output"
|
| 99 |
IMAGE_DIR = DATA_DIR / "img"
|
| 100 |
TIMEZONE = ZoneInfo("Asia/Singapore")
|
|
@@ -133,14 +129,12 @@ STARTUP_ASSET_IDS = {
|
|
| 133 |
}
|
| 134 |
ENVIRONMENT_START = .2
|
| 135 |
REGIONAL_GLOBAL_STRENGTH = .6
|
| 136 |
-
|
| 137 |
-
"ComfyUI-Impact-Pack"
|
| 138 |
-
"ComfyUI-Impact-Subpack"
|
| 139 |
-
"ComfyUI-ppm"
|
| 140 |
-
"ComfyUI_IPAdapter_plus"
|
| 141 |
-
|
| 142 |
-
),
|
| 143 |
-
}
|
| 144 |
CUSTOM_NODE_MODULES = {
|
| 145 |
"ComfyUI-Impact-Pack": (
|
| 146 |
"segment_anything", "skimage", "piexif", "transformers", "cv2",
|
|
@@ -728,43 +722,15 @@ def ensure_comfy():
|
|
| 728 |
|
| 729 |
|
| 730 |
def ensure_custom_nodes():
|
| 731 |
-
|
| 732 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 733 |
target = CUSTOM_NODES_DIR / name
|
| 734 |
-
|
| 735 |
-
|
| 736 |
-
["git", "clone", "--depth", "1", url, str(target)],
|
| 737 |
-
check=True,
|
| 738 |
-
)
|
| 739 |
-
|
| 740 |
-
for target in CUSTOM_NODES_DIR.iterdir():
|
| 741 |
-
if not target.is_dir():
|
| 742 |
-
continue
|
| 743 |
-
if (target / ".git").exists():
|
| 744 |
-
local = subprocess.check_output(
|
| 745 |
-
["git", "-C", str(target), "rev-parse", "HEAD"],
|
| 746 |
-
text=True,
|
| 747 |
-
).strip()
|
| 748 |
-
subprocess.run(
|
| 749 |
-
[
|
| 750 |
-
"git", "-C", str(target), "fetch", "--depth", "1",
|
| 751 |
-
"origin", "HEAD",
|
| 752 |
-
],
|
| 753 |
-
check=True,
|
| 754 |
-
)
|
| 755 |
-
remote = subprocess.check_output(
|
| 756 |
-
["git", "-C", str(target), "rev-parse", "FETCH_HEAD"],
|
| 757 |
-
text=True,
|
| 758 |
-
).strip()
|
| 759 |
-
if local != remote:
|
| 760 |
-
# These are managed dependencies. Persistent copies can diverge
|
| 761 |
-
# after an upstream force-push or an interrupted deployment, so
|
| 762 |
-
# a fast-forward-only pull is not sufficient.
|
| 763 |
-
subprocess.run(
|
| 764 |
-
["git", "-C", str(target), "reset", "--hard", remote],
|
| 765 |
-
check=True,
|
| 766 |
-
)
|
| 767 |
-
modules = CUSTOM_NODE_MODULES.get(target.name)
|
| 768 |
if modules and not any(importlib.util.find_spec(item) is None for item in modules):
|
| 769 |
continue
|
| 770 |
requirements = target / "requirements.txt"
|
|
|
|
| 90 |
LOCAL_MODEL_DIR = Path(os.environ.get("LOCAL_MODEL_DIR", "/tmp/models"))
|
| 91 |
COMFYUI_PATH = Path(os.environ.get("COMFYUI_PATH", Path.cwd() / "ComfyUI"))
|
| 92 |
MOUNTED_CUSTOM_NODES_DIR = BUCKET_MOUNT / "custom_nodes"
|
| 93 |
+
CUSTOM_NODES_DIR = Path("/tmp/custom_nodes")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
OUTPUT_DIR = DATA_DIR / "output"
|
| 95 |
IMAGE_DIR = DATA_DIR / "img"
|
| 96 |
TIMEZONE = ZoneInfo("Asia/Singapore")
|
|
|
|
| 129 |
}
|
| 130 |
ENVIRONMENT_START = .2
|
| 131 |
REGIONAL_GLOBAL_STRENGTH = .6
|
| 132 |
+
REQUIRED_CUSTOM_NODES = (
|
| 133 |
+
"ComfyUI-Impact-Pack",
|
| 134 |
+
"ComfyUI-Impact-Subpack",
|
| 135 |
+
"ComfyUI-ppm",
|
| 136 |
+
"ComfyUI_IPAdapter_plus",
|
| 137 |
+
)
|
|
|
|
|
|
|
| 138 |
CUSTOM_NODE_MODULES = {
|
| 139 |
"ComfyUI-Impact-Pack": (
|
| 140 |
"segment_anything", "skimage", "piexif", "transformers", "cv2",
|
|
|
|
| 722 |
|
| 723 |
|
| 724 |
def ensure_custom_nodes():
|
| 725 |
+
shutil.rmtree(CUSTOM_NODES_DIR, ignore_errors=True)
|
| 726 |
+
CUSTOM_NODES_DIR.mkdir(parents=True)
|
| 727 |
+
for name in REQUIRED_CUSTOM_NODES:
|
| 728 |
+
source = MOUNTED_CUSTOM_NODES_DIR / name
|
| 729 |
+
if not source.is_dir():
|
| 730 |
+
raise FileNotFoundError(f"Missing required custom node: {source}")
|
| 731 |
target = CUSTOM_NODES_DIR / name
|
| 732 |
+
target.symlink_to(source, target_is_directory=True)
|
| 733 |
+
modules = CUSTOM_NODE_MODULES.get(name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 734 |
if modules and not any(importlib.util.find_spec(item) is None for item in modules):
|
| 735 |
continue
|
| 736 |
requirements = target / "requirements.txt"
|