| import os |
| import sys |
| import shutil |
|
|
| from core.settings import * |
|
|
| def move_and_overwrite(src, dst): |
| if os.path.isdir(src): |
| os.makedirs(dst, exist_ok=True) |
| for item in os.listdir(src): |
| s_child = os.path.join(src, item) |
| d_child = os.path.join(dst, item) |
| move_and_overwrite(s_child, d_child) |
| elif os.path.isfile(src): |
| if os.path.exists(dst): |
| try: |
| os.remove(dst) |
| except OSError: |
| pass |
| shutil.move(src, dst) |
|
|
| def initialize_comfyui(): |
| APP_DIR = sys.path[0] |
| COMFYUI_TEMP_DIR = "ComfyUI_temp" |
|
|
| print("--- Cloning ComfyUI Repository ---") |
| if not os.path.exists(COMFYUI_TEMP_DIR): |
| os.system(f"git clone https://github.com/comfy-Org/ComfyUI {COMFYUI_TEMP_DIR}") |
| print("✅ ComfyUI repository cloned.") |
| else: |
| print("✅ ComfyUI repository already exists.") |
|
|
| print(f"--- Merging ComfyUI from '{COMFYUI_TEMP_DIR}' to '{APP_DIR}' ---") |
| for item in os.listdir(COMFYUI_TEMP_DIR): |
| src_path = os.path.join(COMFYUI_TEMP_DIR, item) |
| dst_path = os.path.join(APP_DIR, item) |
| if item == '.git': |
| continue |
| move_and_overwrite(src_path, dst_path) |
| |
| try: |
| shutil.rmtree(COMFYUI_TEMP_DIR) |
| print("✅ ComfyUI merged and temporary directory removed.") |
| except OSError as e: |
| print(f"⚠️ Could not remove temporary directory '{COMFYUI_TEMP_DIR}': {e}") |
|
|
|
|
|
|
|
|
| print(f"✅ Current working directory is: {os.getcwd()}") |
| |
| import comfy.model_management |
| print("--- Environment Ready ---") |
|
|
| print("✅ ComfyUI initialized with default attention mechanism.") |
|
|
| try: |
| import comfy.sd |
| orig_vae_init = comfy.sd.VAE.__init__ |
| def patched_vae_init(self, *args, **kwargs): |
| orig_vae_init(self, *args, **kwargs) |
| self.process_output = lambda image: (image.clone() if getattr(image, 'is_inference', False) else image).add_(1.0).div_(2.0).clamp_(0.0, 1.0) |
| comfy.sd.VAE.__init__ = patched_vae_init |
| print("✅ Applied VAE process_output inference tensor safety patch.") |
| except Exception as e: |
| print(f"⚠️ Could not patch VAE process_output: {e}") |
|
|
| for dir_path in CATEGORY_TO_DIR_MAP.values(): |
| os.makedirs(os.path.join(APP_DIR, dir_path), exist_ok=True) |
| |
| os.makedirs(os.path.join(APP_DIR, INPUT_DIR), exist_ok=True) |
| os.makedirs(os.path.join(APP_DIR, OUTPUT_DIR), exist_ok=True) |
| |
| print("✅ All required model directories are present.") |