Compare commits

...
Author SHA1 Message Date
karrix 02f499a4dc add: name 2024-10-23 19:07:42 +08:00
karrix 67d27bd4aa add: any output 2024-10-23 18:47:58 +08:00
karrix 8ee2f88e72 tweak 2024-10-22 17:51:04 +08:00
karrix c17a029173 tweak: back to support all 2024-10-22 17:34:33 +08:00
karrix c82f0c2bf0 tweak 2024-10-22 14:56:06 +08:00
karrix fdbf24207f tweak 2024-10-22 14:04:37 +08:00
karrix 0a9d0d3e3e tweak 2024-10-22 13:57:19 +08:00
karrix d41c4de352 init 2024-10-22 12:54:33 +08:00
BennyKok 0779136134 Update pyproject.toml 2024-10-22 11:28:59 +08:00
nick fe116a4655 clean logs 2024-10-12 23:59:58 -07:00
nick 7dd8a7e67e gpu eveent 2024-10-12 16:57:37 -07:00
4 changed files with 141 additions and 9 deletions
+46
View File
@@ -0,0 +1,46 @@
import json
class AnyType(str):
"""A special class that is always equal in not equal comparisons. Credit to pythongosssss"""
def __ne__(self, __value: object) -> bool:
return False
any = AnyType("*")
class ComfyDeployStdOutputAny:
@classmethod
def INPUT_TYPES(cls): # pylint: disable = invalid-name, missing-function-docstring
return {
"required": {
"name": ("STRING", {"default": "ComfyUI"}),
"source": (any, {}), # Use "*" to accept any input type
},
}
CATEGORY = "output"
RETURN_TYPES = ()
FUNCTION = "run"
OUTPUT_NODE = True
def run(self, name, source=None):
value = "None"
if source is not None:
try:
value = json.dumps(source)
except Exception:
try:
value = str(source)
except Exception:
value = "source exists, but could not be serialized."
return {"ui": {name: (value,)}}
NODE_CLASS_MAPPINGS = {"ComfyDeployStdOutputAny": ComfyDeployStdOutputAny}
NODE_DISPLAY_NAME_MAPPINGS = {
"ComfyDeployStdOutputAny": "Standard Any Output (ComfyDeploy)"
}
+92
View File
@@ -0,0 +1,92 @@
import os
import json
import numpy as np
from PIL import Image
from PIL.PngImagePlugin import PngInfo
import folder_paths
class ComfyDeployStdOutputImage:
def __init__(self):
self.output_dir = folder_paths.get_output_directory()
self.type = "output"
self.prefix_append = ""
self.compress_level = 4
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"images": ("IMAGE", {"tooltip": "The images to save."}),
"filename_prefix": (
"STRING",
{
"default": "ComfyUI",
"tooltip": "The prefix for the file to save. This may include formatting information such as %date:yyyy-MM-dd% or %Empty Latent Image.width% to include values from nodes.",
},
),
"file_type": (["png", "jpg", "webp"], {"default": "webp"}),
"quality": ("INT", {"default": 80, "min": 1, "max": 100, "step": 1}),
},
"hidden": {"prompt": "PROMPT", "extra_pnginfo": "EXTRA_PNGINFO"},
}
RETURN_TYPES = ()
FUNCTION = "run"
OUTPUT_NODE = True
CATEGORY = "output"
DESCRIPTION = "Saves the input images to your ComfyUI output directory."
def run(
self,
images,
filename_prefix="ComfyUI",
file_type="png",
quality=80,
prompt=None,
extra_pnginfo=None,
):
filename_prefix += self.prefix_append
full_output_folder, filename, counter, subfolder, filename_prefix = (
folder_paths.get_save_image_path(
filename_prefix, self.output_dir, images[0].shape[1], images[0].shape[0]
)
)
results = list()
for batch_number, image in enumerate(images):
i = 255.0 * image.cpu().numpy()
img = Image.fromarray(np.clip(i, 0, 255).astype(np.uint8))
metadata = PngInfo()
if prompt is not None:
metadata.add_text("prompt", json.dumps(prompt))
if extra_pnginfo is not None:
for x in extra_pnginfo:
metadata.add_text(x, json.dumps(extra_pnginfo[x]))
filename_with_batch_num = filename.replace("%batch_num%", str(batch_number))
file = f"{filename_with_batch_num}_{counter:05}_.{file_type}"
file_path = os.path.join(full_output_folder, file)
if file_type == "png":
img.save(
file_path, pnginfo=metadata, compress_level=self.compress_level
)
elif file_type == "jpg":
img.save(file_path, quality=quality, optimize=True)
elif file_type == "webp":
img.save(file_path, quality=quality)
results.append(
{"filename": file, "subfolder": subfolder, "type": self.type}
)
counter += 1
return {"ui": {"images": results}}
NODE_CLASS_MAPPINGS = {"ComfyDeployStdOutputImage": ComfyDeployStdOutputImage}
NODE_DISPLAY_NAME_MAPPINGS = {
"ComfyDeployStdOutputImage": "Standard Image Output (ComfyDeploy)"
}
+2 -8
View File
@@ -296,7 +296,6 @@ def apply_random_seed_to_workflow(workflow_api):
Args: Args:
workflow_api (dict): The workflow API dictionary to modify. workflow_api (dict): The workflow API dictionary to modify.
""" """
print("workflow_api", workflow_api)
for key in workflow_api: for key in workflow_api:
if "inputs" in workflow_api[key]: if "inputs" in workflow_api[key]:
if "seed" in workflow_api[key]["inputs"]: if "seed" in workflow_api[key]["inputs"]:
@@ -468,7 +467,6 @@ async def comfy_deploy_run(request):
if len(parts) == 2 and parts[0].lower() == "bearer": if len(parts) == 2 and parts[0].lower() == "bearer":
token = parts[1] token = parts[1]
print("RECIEVED DATA", data)
# In older version, we use workflow_api, but this has inputs already swapped in nextjs frontend, which is tricky # In older version, we use workflow_api, but this has inputs already swapped in nextjs frontend, which is tricky
workflow_api = data.get("workflow_api_raw") workflow_api = data.get("workflow_api_raw")
# The prompt id generated from comfy deploy, can be None # The prompt id generated from comfy deploy, can be None
@@ -542,6 +540,7 @@ async def stream_prompt(data, token):
prompt_id = data.get("prompt_id") prompt_id = data.get("prompt_id")
inputs = data.get("inputs") inputs = data.get("inputs")
workflow = data.get("workflow") workflow = data.get("workflow")
gpu_event_id = data.get("gpu_event_id", None)
# Now it handles directly in here # Now it handles directly in here
apply_random_seed_to_workflow(workflow_api) apply_random_seed_to_workflow(workflow_api)
@@ -559,6 +558,7 @@ async def stream_prompt(data, token):
file_upload_endpoint=data.get("file_upload_endpoint"), file_upload_endpoint=data.get("file_upload_endpoint"),
workflow_api=workflow_api, workflow_api=workflow_api,
token=token, token=token,
gpu_event_id=gpu_event_id,
) )
# log('info', "Begin prompt", prompt=prompt) # log('info', "Begin prompt", prompt=prompt)
@@ -1287,7 +1287,6 @@ async def update_run_ws_event(prompt_id: str, event: str, data: dict):
if prompt_id not in prompt_metadata: if prompt_id not in prompt_metadata:
return return
# print("update_run_ws_event", prompt_id, event, data)
status_endpoint = prompt_metadata[prompt_id].status_endpoint status_endpoint = prompt_metadata[prompt_id].status_endpoint
if status_endpoint is None: if status_endpoint is None:
@@ -1296,11 +1295,6 @@ async def update_run_ws_event(prompt_id: str, event: str, data: dict):
token = prompt_metadata[prompt_id].token token = prompt_metadata[prompt_id].token
gpu_event_id = prompt_metadata[prompt_id].gpu_event_id or None gpu_event_id = prompt_metadata[prompt_id].gpu_event_id or None
print("prompt_metadata", prompt_metadata[prompt_id])
print("gpu_event_id", gpu_event_id)
print("event", event)
print("data", data)
body = { body = {
"run_id": prompt_id, "run_id": prompt_id,
"ws_event": { "ws_event": {
+1 -1
View File
@@ -1,7 +1,7 @@
[project] [project]
name = "comfyui-deploy" name = "comfyui-deploy"
description = "Open source comfyui deployment platform, a vercel for generative workflow infra." description = "Open source comfyui deployment platform, a vercel for generative workflow infra."
version = "1.0.0" version = "1.1.0"
license = "LICENSE" license = "LICENSE"
dependencies = ["aiofiles", "pydantic", "opencv-python", "imageio-ffmpeg"] dependencies = ["aiofiles", "pydantic", "opencv-python", "imageio-ffmpeg"]