diff --git a/.idea/misc.xml b/.idea/misc.xml index 8b6e169..c7eed4e 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,5 +3,5 @@ - + \ No newline at end of file diff --git a/.idea/modalDeploy.iml b/.idea/modalDeploy.iml index b262e37..a661ebe 100644 --- a/.idea/modalDeploy.iml +++ b/.idea/modalDeploy.iml @@ -4,7 +4,7 @@ - + \ No newline at end of file diff --git a/server_with_s3.py b/server_with_s3.py index 55972fe..f1d40be 100644 --- a/server_with_s3.py +++ b/server_with_s3.py @@ -52,10 +52,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("comfy node install https://e.coding.net/g-ldyi2063/dev/ComfyUI-CustomNode.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/cosyvoice_comfyui.git") .run_commands("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/ComfyUI-CustomNode.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( @@ -120,13 +120,15 @@ class ComfyUI: @modal.enter() 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".format(self.session_id,self.session_id, self.session_id) + subprocess.run(cmd, shell=True, check=True) cmd = "comfy launch --background" subprocess.run(cmd, shell=True, check=True) @modal.method() def infer(self, workflow_json: str = ""): # runs the comfy run --workflow command as a subprocess - session_id = str(uuid.uuid4()) workflow = json.loads(workflow_json) for node in workflow.values(): if node.get("class_type") == "ComfyUIDeployExternalText": @@ -136,9 +138,9 @@ class ComfyUI: os.makedirs(os.path.dirname(file_to_move.replace("input_s3", "input")), exist_ok=True) shutil.copy(file_to_move, file_to_move.replace("input_s3", "input")) node["inputs"]["default_value"] = node["inputs"]["default_value"].replace("input_s3", "input") - with open(f"/root/{session_id}.json", "w", encoding="utf-8") as f: + with open(f"/root/{self.session_id}.json", "w", encoding="utf-8") as f: f.write(json.dumps(workflow, ensure_ascii=False)) - cmd = f"comfy run --workflow /root/{session_id}.json --wait --timeout 900 --verbose" + cmd = f"comfy run --workflow /root/{self.session_id}.json --wait --timeout 900 --verbose" subprocess.run(cmd, shell=True, check=True) # looks up the name of the output image file based on the workflow @@ -160,7 +162,7 @@ class ComfyUI: shutil.copy(os.path.join(output_dir, f), os.path.join(output_dir.replace("output", "output_s3"), f)) return f - @modal.web_endpoint(method="POST") + @modal.fastapi_endpoint(method="POST") def api(self, item: Dict): from fastapi import Response