diff --git a/src/cluster/comfyui_v1.py b/src/cluster/comfyui_v1.py index fa346fd..469db92 100644 --- a/src/cluster/comfyui_v1.py +++ b/src/cluster/comfyui_v1.py @@ -11,8 +11,7 @@ comfyui_image = ( .run_commands("add-apt-repository -y contrib " "&& wget https://developer.download.nvidia.com/compute/cuda/repos/debian12/x86_64/cuda-keyring_1.1-1_all.deb&&dpkg -i cuda-keyring_1.1-1_all.deb") .apt_install("git", "gcc", "libportaudio2", "cuda-toolkit", "ffmpeg") - .add_local_file("../whl/comfy_cli-0.0.0-py3-none-any.whl", "/root/comfy_cli-0.0.0-py3-none-any.whl",copy=True) - .pip_install("/root/comfy_cli-0.0.0-py3-none-any.whl") + .pip_install("comfy_cli==0.0.0", index_url="https://packages-1747622887395:0ee15474ccd7b27b57ca63a9306327678e6c2631@g-ldyi2063-pypi.pkg.coding.net/dev/packages/simple") .run_commands("comfy --skip-prompt install --nvidia --version 0.3.10") .env(dotenv_values("../.runtime.env")) .workdir("/root/comfy") @@ -50,8 +49,6 @@ comfyui_image = ( ).run_commands( "rm -rf /root/comfy/ComfyUI/models" ) - .add_local_file("../config/config.yaml", "/root/comfy/ComfyUI/custom_nodes/ComfyUI-CustomNode/config.yaml",copy=True) - .add_local_file("../config/config.py","/root/comfy/ComfyUI/custom_nodes/cosyvoice_comfyui/pretrained_models/tools/config.py",copy=True) .add_local_file("BowongModalFunctions/template/template_v1.json", "/root/src/BowongModalFunctions/template/template_v1.json", copy=True) .add_local_python_source('BowongModalFunctions') .add_local_python_source('cluster') @@ -90,6 +87,7 @@ with comfyui_image.imports(): config = WorkerConfig() vol = modal.Volume.from_name("comfyui-model", create_if_missing=True, environment_name=config.modal_environment) secret = modal.Secret.from_name("aws-s3-secret", environment_name=config.modal_environment) + custom_secret = modal.Secret.from_name("comfyui-custom-secret", environment_name=config.modal_environment) output_dir = "/root/comfy/ComfyUI/output" sentry_sdk.init( @@ -124,7 +122,7 @@ with comfyui_image.imports(): cpu=(2, 64), memory=(20480, 131072), enable_memory_snapshot=False, - secrets=[secret], + secrets=[secret, custom_secret], volumes={ "/root/comfy/ComfyUI/models": vol, "/root/comfy/ComfyUI/input_s3": modal.CloudBucketMount( @@ -163,8 +161,7 @@ with comfyui_image.imports(): async def infer(workflow: Dict): self.poll_server_health() self.prompt_uuid = str(uuid.uuid4()) - print("Workflow JSON:") - print(json.dumps(workflow, indent=4, ensure_ascii=False)) + loguru.logger.info(f"Workflow JSON: \n{json.dumps(workflow, indent=4, ensure_ascii=False)}") for node in workflow.values(): if node.get("class_type") == "ComfyUIDeployExternalText": if node.get("inputs").get("input_id") == "file_path": @@ -179,9 +176,12 @@ with comfyui_image.imports(): # S3 Fallback import boto3 import yaml - with open("/root/comfy/ComfyUI/custom_nodes/ComfyUI-CustomNode/config.yaml", - encoding="utf-8", mode="r+") as myconfig: - yaml_config = yaml.load(myconfig, Loader=yaml.FullLoader) + if "aws_key_id" in list(os.environ.keys()): + yaml_config = os.environ + else: + with open("/root/comfy/ComfyUI/custom_nodes/ComfyUI-CustomNode/config.yaml", + encoding="utf-8", mode="r+") as myconfig: + yaml_config = yaml.load(myconfig, Loader=yaml.FullLoader) awss3 = boto3.resource('s3', aws_access_key_id=yaml_config["aws_key_id"], aws_secret_access_key=yaml_config["aws_access_key"]) awss3.meta.client.download_file(config.S3_bucket_name, @@ -220,9 +220,12 @@ with comfyui_image.imports(): # S3 Fallback import boto3 import yaml - with open("/root/comfy/ComfyUI/custom_nodes/ComfyUI-CustomNode/config.yaml", - encoding="utf-8", mode="r+") as myconfig: - yaml_config = yaml.load(myconfig, Loader=yaml.FullLoader) + if "aws_key_id" in list(os.environ.keys()): + yaml_config = os.environ + else: + with open("/root/comfy/ComfyUI/custom_nodes/ComfyUI-CustomNode/config.yaml", + encoding="utf-8", mode="r+") as myconfig: + yaml_config = yaml.load(myconfig, Loader=yaml.FullLoader) awss3 = boto3.resource('s3', aws_access_key_id=yaml_config["aws_key_id"], aws_secret_access_key=yaml_config["aws_access_key"]) awss3.meta.client.upload_file(os.path.join(output_dir, f), config.S3_bucket_name, diff --git a/src/cluster/comfyui_v2.py b/src/cluster/comfyui_v2.py index 632b775..89415c1 100644 --- a/src/cluster/comfyui_v2.py +++ b/src/cluster/comfyui_v2.py @@ -11,8 +11,7 @@ comfyui_latentsync_1_5_image = ( .run_commands("add-apt-repository -y contrib " "&& wget https://developer.download.nvidia.com/compute/cuda/repos/debian12/x86_64/cuda-keyring_1.1-1_all.deb&&dpkg -i cuda-keyring_1.1-1_all.deb") .apt_install("git", "gcc", "libportaudio2", "cuda-toolkit", "ffmpeg") - .add_local_file("../whl/comfy_cli-0.0.0-py3-none-any.whl", "/root/comfy_cli-0.0.0-py3-none-any.whl", copy=True) - .pip_install("/root/comfy_cli-0.0.0-py3-none-any.whl") + .pip_install("comfy_cli==0.0.0", index_url="https://packages-1747622887395:0ee15474ccd7b27b57ca63a9306327678e6c2631@g-ldyi2063-pypi.pkg.coding.net/dev/packages/simple") .run_commands("comfy --skip-prompt install --nvidia --version 0.3.10") .env(dotenv_values("../.runtime.env")) .workdir("/root/comfy") @@ -50,8 +49,6 @@ comfyui_latentsync_1_5_image = ( ).run_commands( "rm -rf /root/comfy/ComfyUI/models" ) - .add_local_file("../config/config.yaml", "/root/comfy/ComfyUI/custom_nodes/ComfyUI-CustomNode/config.yaml", copy=True) - .add_local_file("../config/config.py", "/root/comfy/ComfyUI/custom_nodes/cosyvoice_comfyui/pretrained_models/tools/config.py", copy=True) .add_local_file("BowongModalFunctions/template/template_v2.json", "/root/src/BowongModalFunctions/template/template_v2.json", copy=True) .add_local_python_source('cluster') .add_local_python_source('BowongModalFunctions') @@ -84,6 +81,7 @@ with comfyui_latentsync_1_5_image.imports(): config = WorkerConfig() vol = modal.Volume.from_name("comfyui-model", create_if_missing=True, environment_name=config.modal_environment) secret = modal.Secret.from_name("aws-s3-secret", environment_name=config.modal_environment) + custom_secret = modal.Secret.from_name("comfyui-custom-secret", environment_name=config.modal_environment) output_dir = "/root/comfy/ComfyUI/output" sentry_sdk.init( @@ -116,7 +114,7 @@ with comfyui_latentsync_1_5_image.imports(): cpu=(2,64), memory=(20480,131072), enable_memory_snapshot=False, - secrets=[secret], + secrets=[secret, custom_secret], volumes={ "/root/comfy/ComfyUI/models": vol, "/root/comfy/ComfyUI/input_s3": modal.CloudBucketMount( @@ -154,8 +152,7 @@ with comfyui_latentsync_1_5_image.imports(): async def infer(workflow: Dict): self.poll_server_health() self.prompt_uuid = str(uuid.uuid4()) - print("Workflow JSON:") - print(json.dumps(workflow, indent=4, ensure_ascii=False)) + loguru.logger.info(f"Workflow JSON: \n{json.dumps(workflow, indent=4, ensure_ascii=False)}") for node in workflow.values(): if node.get("class_type") == "ComfyUIDeployExternalText": if node.get("inputs").get("input_id") == "file_path": @@ -170,9 +167,12 @@ with comfyui_latentsync_1_5_image.imports(): # S3 Fallback import boto3 import yaml - with open("/root/comfy/ComfyUI/custom_nodes/ComfyUI-CustomNode/config.yaml", - encoding="utf-8", mode="r+") as myconfig: - yaml_config = yaml.load(myconfig, Loader=yaml.FullLoader) + if "aws_key_id" in list(os.environ.keys()): + yaml_config = os.environ + else: + with open("/root/comfy/ComfyUI/custom_nodes/ComfyUI-CustomNode/config.yaml", + encoding="utf-8", mode="r+") as myconfig: + yaml_config = yaml.load(myconfig, Loader=yaml.FullLoader) awss3 = boto3.resource('s3', aws_access_key_id=yaml_config["aws_key_id"], aws_secret_access_key=yaml_config["aws_access_key"]) awss3.meta.client.download_file(config.S3_bucket_name, @@ -212,9 +212,12 @@ with comfyui_latentsync_1_5_image.imports(): # S3 Fallback import boto3 import yaml - with open("/root/comfy/ComfyUI/custom_nodes/ComfyUI-CustomNode/config.yaml", - encoding="utf-8", mode="r+") as myconfig: - yaml_config = yaml.load(myconfig, Loader=yaml.FullLoader) + if "aws_key_id" in list(os.environ.keys()): + yaml_config = os.environ + else: + with open("/root/comfy/ComfyUI/custom_nodes/ComfyUI-CustomNode/config.yaml", + encoding="utf-8", mode="r+") as myconfig: + yaml_config = yaml.load(myconfig, Loader=yaml.FullLoader) awss3 = boto3.resource('s3', aws_access_key_id=yaml_config["aws_key_id"], aws_secret_access_key=yaml_config["aws_access_key"]) awss3.meta.client.upload_file(os.path.join(output_dir, f), config.S3_bucket_name,