From 1af3a4c794b91af9cf1dc7a6577b2fcf12ecece0 Mon Sep 17 00:00:00 2001 From: "kyj@bowong.ai" Date: Wed, 30 Apr 2025 13:44:58 +0800 Subject: [PATCH] =?UTF-8?q?FIX=20=E5=B7=B2=E6=9C=89=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E4=BF=AE=E5=A4=8Dcomfy-cli=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server_with_s3.py | 51 +++++++++++++++++++++++++++--------------- server_with_s3_auth.py | 4 ++-- 2 files changed, 35 insertions(+), 20 deletions(-) diff --git a/server_with_s3.py b/server_with_s3.py index 813d681..704e799 100644 --- a/server_with_s3.py +++ b/server_with_s3.py @@ -17,7 +17,13 @@ image = ( # build up a Modal Image to run ComfyUI, step by step .apt_install("gcc") .apt_install("libportaudio2") .pip_install("fastapi[standard]==0.115.4") # install web dependencies - .pip_install("comfy-cli==1.3.5") # install comfy-cli + .apt_install("software-properties-common", force_build=True) + .apt_install("wget") + .run_commands("add-apt-repository -y contrib") + .run_commands("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("cuda-toolkit") + .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") # install modified-comfy-cli .pip_install("cos-python-sdk-v5") .pip_install("sqlalchemy") .pip_install("ultralytics") @@ -52,10 +58,10 @@ image = ( .run_commands("comfy node install https://github.com/rgthree/rgthree-comfy") .run_commands("comfy node install https://github.com/cubiq/ComfyUI_essentials") .run_commands("comfy node install https://github.com/melMass/comfy_mtb") - .run_commands("echo 3 && comfy node install https://e.coding.net/g-ldyi2063/dev/ComfyUI_SparkTTS.git") + .run_commands("comfy node install https://e.coding.net/g-ldyi2063/dev/ComfyUI_SparkTTS.git") .run_commands("comfy node install https://e.coding.net/g-ldyi2063/dev/ComfyUI-CustomNode.git") - .run_commands("echo 04111 && comfy node install https://e.coding.net/g-ldyi2063/dev/cosyvoice_comfyui.git") - .run_commands("echo 4 && comfy node install https://e.coding.net/g-ldyi2063/dev/ComfyUI-LatentSync-Node.git") + .run_commands("comfy node install https://e.coding.net/g-ldyi2063/dev/cosyvoice_comfyui.git") + .run_commands("comfy node install https://e.coding.net/g-ldyi2063/dev/ComfyUI-LatentSync-Node.git") .run_commands( "mkdir -p /root/comfy/ComfyUI/models/ComfyUI-CustomNode/model && rm -rf /root/comfy/ComfyUI/custom_nodes/ComfyUI-CustomNode/model && ln -s /root/comfy/ComfyUI/models/ComfyUI-CustomNode/model /root/comfy/ComfyUI/custom_nodes/ComfyUI-CustomNode/model" ).run_commands( @@ -94,11 +100,11 @@ output_dir = "/root/comfy/ComfyUI/output" buffer_containers=0, scaledown_window=120, # 5 minute container keep alive after it processes an input; increasing this value is a great way to reduce ComfyUI cold start times - timeout=900, + timeout=1200, gpu=["L4", "T4"], cpu=(2,16), # memory=(32768, 32768), # (内存预留量, 内存使用上限) - memory=(20480,40960), + memory=(20480,65536), enable_memory_snapshot=False, secrets=[secret], volumes={ @@ -122,7 +128,7 @@ class ComfyUI: def launch_comfy_background(self): # starts the ComfyUI server in the background exactly once when the first input is received self.session_id = str(uuid.uuid4()) - cmd = "echo client_uuid: {}&&rm -rf /root/comfy/ComfyUI/user&&mkdir -p /root/comfy/ComfyUI/output_s3/logs/{}&&ln -s /root/comfy/ComfyUI/output_s3/logs/{} /root/comfy/ComfyUI/user && comfy launch --background".format(self.session_id,self.session_id, self.session_id) + cmd = "echo client_uuid: {}&& mkdir -p /root/comfy/ComfyUI/output_s3/logs/{} && comfy launch --background".format(self.session_id,self.session_id, self.session_id) subprocess.run(cmd, shell=True, check=True) @modal.method() @@ -143,7 +149,7 @@ class ComfyUI: shutil.copy(file_to_move, file_to_move.replace("input_s3", "input")) except: try: - print("Try download file to S3 manually") + print("Try download file from S3 manually") # S3 Fallback import boto3 import yaml @@ -159,16 +165,17 @@ class ComfyUI: node["inputs"]["default_value"] = node["inputs"]["default_value"].replace("input_s3", "input") with open(f"/root/{self.prompt_uuid}.json", "w", encoding="utf-8") as f: f.write(json.dumps(workflow, ensure_ascii=False)) - cmd = f"comfy run --workflow /root/{self.prompt_uuid}.json --wait --timeout 890 --verbose" - subprocess.run(cmd, shell=True, check=True, timeout=895) - + cmd = f"comfy run --workflow /root/{self.prompt_uuid}.json --wait --timeout 1190 --verbose" # looks up the name of the output image file based on the workflow - file_prefix = [ + self.file_prefix = [ node.get("inputs") for node in workflow.values() if node.get("class_type") == "VHS_VideoCombine" ][0]["filename_prefix"] + subprocess.run(cmd, shell=True, check=True, timeout=1195) + + # returns the image as bytes file_list = os.listdir(output_dir) # 获取按照文件时间创建排序的列表,默认是按时间升序 @@ -176,7 +183,7 @@ class ComfyUI: reverse=True) # print("file_list", new_file_list) for f in new_file_list: - if f.startswith(file_prefix): + if f.startswith(self.file_prefix): os.makedirs(os.path.dirname(os.path.join(output_dir.replace("output", "output_s3"), f)), exist_ok=True) try: shutil.copy(os.path.join(output_dir, f), os.path.join(output_dir.replace("output", "output_s3"), f)) @@ -217,6 +224,19 @@ class ComfyUI: subprocess.run(cmd, shell=True, check=True) except: pass + print("Summary Logs") + try: + with open("/root/comfy/ComfyUI/user/comfyui.log", "r", encoding="utf-8") as f: + log_text = f"\n-----------{self.file_prefix}------------\n"+f.read()+"\n" + if os.path.exists(f"/root/comfy/ComfyUI/output_s3/logs/{self.session_id}/full.txt"): + with open(f"/root/comfy/ComfyUI/output_s3/logs/{self.session_id}/full.txt", "r", encoding="utf-8") as f: + log_text = f.read() + log_text + with open(f"/root/comfy/ComfyUI/output_s3/logs/{self.session_id}/full.txt", "w", encoding="utf-8") as f: + f.write(log_text) + if os.path.exists(f"/root/comfy/ComfyUI/user/ffmpeg.txt"): + shutil.copy("/root/comfy/ComfyUI/user/ffmpeg.txt", f"/root/comfy/ComfyUI/output_s3/logs/{self.session_id}/ffmpeg.txt") + except Exception as e: + print(f"Summary Logs Failed: {e}") cmd = "comfy launch --background" try: subprocess.run(cmd, shell=True, check=True) @@ -251,8 +271,3 @@ class ComfyUI: modal.experimental.stop_fetching_inputs() raise Exception("ComfyUI server is not healthy, restart failed, stopping container") - # @modal.web_endpoint(method="POST", label="tk") - # def tk_api(self, item: Dict): - # pass - # - diff --git a/server_with_s3_auth.py b/server_with_s3_auth.py index 866e2c7..6133a1a 100644 --- a/server_with_s3_auth.py +++ b/server_with_s3_auth.py @@ -107,7 +107,7 @@ auth_scheme = HTTPBearer() gpu=["L4", "T4"], cpu=(2,16), # memory=(32768, 32768), # (内存预留量, 内存使用上限) - memory=(32768,131072), + memory=(20480,131072), enable_memory_snapshot=False, secrets=[secret, modal.Secret.from_name("web_auth_token")], volumes={ @@ -152,7 +152,7 @@ class ComfyUI: shutil.copy(file_to_move, file_to_move.replace("input_s3", "input")) except: try: - print("Try download file to S3 manually") + print("Try download file from S3 manually") # S3 Fallback import boto3 import yaml