This commit is contained in:
shenenqing001 2024-05-23 18:46:36 +08:00
parent 11a2ad5110
commit 7bb8679045
4 changed files with 156 additions and 1 deletions

39
Dockerfile Normal file
View File

@ -0,0 +1,39 @@
FROM harbor.intra.ke.com/aistudio/serving/public/arch-inference-serving_dimage:master_202405090948
LABEL authors="shenenqing001"
ARG commit=main
ENV DEBIAN_FRONTEND=noninteractive LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8
ARG CONDA_VERSION=py310_23.3.1-0
RUN pip install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple
RUN pip install opencv-python -i https://pypi.tuna.tsinghua.edu.cn/simple
RUN pip install torch -i https://pypi.tuna.tsinghua.edu.cn/simple
RUN pip install torchsde -i https://pypi.tuna.tsinghua.edu.cn/simple
RUN pip install torchvision -i https://pypi.tuna.tsinghua.edu.cn/simple
RUN pip install einops -i https://pypi.tuna.tsinghua.edu.cn/simple
RUN pip install transformers>=4.25.1 -i https://pypi.tuna.tsinghua.edu.cn/simple
RUN pip install safetensors>=0.3.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
RUN pip install aiohttp -i https://pypi.tuna.tsinghua.edu.cn/simple
RUN pip install pyyaml -i https://pypi.tuna.tsinghua.edu.cn/simple
RUN pip install Pillow -i https://pypi.tuna.tsinghua.edu.cn/simple
RUN pip install scipy -i https://pypi.tuna.tsinghua.edu.cn/simple
RUN pip install tqdm -i https://pypi.tuna.tsinghua.edu.cn/simple
RUN pip install psutil -i https://pypi.tuna.tsinghua.edu.cn/simple
RUN pip install kornia>=0.7.1 -i https://pypi.tuna.tsinghua.edu.cn/simple
RUN rm -rf /workspace
RUN mkdir -p /workspace
RUN mkdir -p /data0/www/applogs/
WORKDIR /workspace
COPY . /workspace/ComfyUI
RUN find /workspace/ComfyUI/custom_nodes -type f -name 'requirements.txt' -exec pip install -r {} \;
ENV TZ=Asia/Shanghai
ENTRYPOINT python /workspace/ComfyUI/main.py

View File

@ -0,0 +1,57 @@
import numpy as np
import pyheif
import cv2
import whatimage
import time
from PIL import Image
import requests
import torch
def image2format(image: bytes):
fmt = whatimage.identify_image(image)
if fmt in ["heic", "avif"]:
i = pyheif.read_heif(image)
image = Image.frombytes(mode=i.mode, size=i.size, data=i.data)
image = cv2.cvtColor(np.asarray(image), cv2.COLOR_RGB2BGR)
else:
image = np.asarray(bytearray(image), dtype=np.uint8)
image = cv2.imdecode(image, cv2.IMREAD_COLOR)
return image
class image_url_node:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"image_url": ("STRING", {"default": "null"}),
},
}
RETURN_TYPES = ("IMAGE",)
FUNCTION = "download_image"
CATEGORY = "image"
def download_image(self, image_url):
res = requests.get(image_url, timeout=3).content
image = image2format(res)
image = image.astype(np.float32) / 255.
image = torch.from_numpy(image)
image = image.unsqueeze(0)
return (image,)
NODE_CLASS_MAPPINGS = {
"image_url_node": image_url_node
}
NODE_DISPLAY_NAME_MAPPINGS = {
"image_url_node": "image_url_node"
}

View File

@ -1,6 +1,8 @@
import base64
from PIL import Image, ImageOps from PIL import Image, ImageOps
from io import BytesIO from io import BytesIO
import numpy as np import numpy as np
import requests
import struct import struct
import comfy.utils import comfy.utils
import time import time
@ -40,6 +42,48 @@ class SaveImageWebsocket:
def IS_CHANGED(s, images): def IS_CHANGED(s, images):
return time.time() return time.time()
class SaveImageHttp:
@classmethod
def INPUT_TYPES(s):
return {"required": {"images": ("IMAGE",),
"callback_url": ("STRING", {"default": "null"})},
}
RETURN_TYPES = ()
FUNCTION = "save_images"
OUTPUT_NODE = True
CATEGORY = "api/image"
def save_images(self, images, callback_url):
pbar = comfy.utils.ProgressBar(images.shape[0])
step = 0
for image in images:
i = 255. * image.cpu().numpy()
img = Image.fromarray(np.clip(i, 0, 255).astype(np.uint8))
buffer = BytesIO()
img.save(buffer, format="PNG")
img_str = base64.b64encode(buffer.getvalue()).decode("utf-8")
pbar.update_absolute(step, images.shape[0], ("PNG", img, None))
step += 1
req = {
"images": img_str,
}
requests.post(url=callback_url, json=req)
return {}
def IS_CHANGED(s, images):
return time.time()
NODE_CLASS_MAPPINGS = { NODE_CLASS_MAPPINGS = {
"SaveImageWebsocket": SaveImageWebsocket, "SaveImageWebsocket": SaveImageWebsocket,
} "SaveImageHttp": SaveImageHttp,
}

View File

@ -44,6 +44,8 @@ def interrupt_processing(value=True):
MAX_RESOLUTION=16384 MAX_RESOLUTION=16384
model_cache = {}
class CLIPTextEncode: class CLIPTextEncode:
@classmethod @classmethod
def INPUT_TYPES(s): def INPUT_TYPES(s):
@ -682,12 +684,16 @@ class VAELoader:
#TODO: scale factor? #TODO: scale factor?
def load_vae(self, vae_name): def load_vae(self, vae_name):
if vae_name in model_cache:
return (model_cache[vae_name],)
if vae_name in ["taesd", "taesdxl"]: if vae_name in ["taesd", "taesdxl"]:
sd = self.load_taesd(vae_name) sd = self.load_taesd(vae_name)
else: else:
vae_path = folder_paths.get_full_path("vae", vae_name) vae_path = folder_paths.get_full_path("vae", vae_name)
sd = comfy.utils.load_torch_file(vae_path) sd = comfy.utils.load_torch_file(vae_path)
vae = comfy.sd.VAE(sd=sd) vae = comfy.sd.VAE(sd=sd)
model_cache[vae_name] = vae
return (vae,) return (vae,)
class ControlNetLoader: class ControlNetLoader:
@ -702,7 +708,10 @@ class ControlNetLoader:
def load_controlnet(self, control_net_name): def load_controlnet(self, control_net_name):
controlnet_path = folder_paths.get_full_path("controlnet", control_net_name) controlnet_path = folder_paths.get_full_path("controlnet", control_net_name)
if controlnet_path in model_cache:
return (model_cache[controlnet_path],)
controlnet = comfy.controlnet.load_controlnet(controlnet_path) controlnet = comfy.controlnet.load_controlnet(controlnet_path)
model_cache[controlnet_path] = controlnet
return (controlnet,) return (controlnet,)
class DiffControlNetLoader: class DiffControlNetLoader:
@ -811,7 +820,10 @@ class UNETLoader:
def load_unet(self, unet_name): def load_unet(self, unet_name):
unet_path = folder_paths.get_full_path("unet", unet_name) unet_path = folder_paths.get_full_path("unet", unet_name)
if unet_path in model_cache:
return (model_cache[unet_path],)
model = comfy.sd.load_unet(unet_path) model = comfy.sd.load_unet(unet_path)
return (model,) return (model,)
class CLIPLoader: class CLIPLoader:
@ -831,7 +843,10 @@ class CLIPLoader:
clip_type = comfy.sd.CLIPType.STABLE_CASCADE clip_type = comfy.sd.CLIPType.STABLE_CASCADE
clip_path = folder_paths.get_full_path("clip", clip_name) clip_path = folder_paths.get_full_path("clip", clip_name)
if clip_path in model_cache:
return (model_cache[clip_path],)
clip = comfy.sd.load_clip(ckpt_paths=[clip_path], embedding_directory=folder_paths.get_folder_paths("embeddings"), clip_type=clip_type) clip = comfy.sd.load_clip(ckpt_paths=[clip_path], embedding_directory=folder_paths.get_folder_paths("embeddings"), clip_type=clip_type)
model_cache[clip_path] = clip
return (clip,) return (clip,)
class DualCLIPLoader: class DualCLIPLoader: