Created
November 9, 2023 19:35
-
-
Save dmarx/5b89755b63e5252a133eca30e0eec975 to your computer and use it in GitHub Desktop.
MWE demonstrating how to use ComfyUI nodes programmatically
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def init_comfy( | |
comfyui_path = "/home/dmarx/projects/ComfyUI" | |
): | |
# 1. add ComyUI to path | |
import sys | |
sys.path.append(comfyui_path) | |
# 2. ensure cli parser doesn't cause issues | |
from comfy.options import enable_args_parsing | |
enable_args_parsing(False) | |
# 3. spin up custom nodes and prompt server | |
import asyncio | |
import server | |
import execution | |
from nodes import init_custom_nodes | |
loop = asyncio.get_event_loop() | |
server_instance = server.PromptServer(loop) | |
execution.PromptQueue(server_instance) | |
init_custom_nodes() | |
init_comfy() | |
from nodes import NODE_CLASS_MAPPINGS | |
import torch | |
with torch.inference_mode(): | |
image_load = NODE_CLASS_MAPPINGS["Image Load"]() | |
clipseg = NODE_CLASS_MAPPINGS["CLIPSeg"]() | |
input_image_data = image_load.load_image( | |
image_path="/home/dmarx/projects/whats-in-a-name/images/a_photo_of_adele_portrait_photography_full_color_face_full_frame/1695441053_3.png", | |
RGBA="false", | |
filename_text_extension="true", | |
)[0] | |
hair_mask = clipseg.segment_image( | |
image=input_image_data, | |
text="hair", | |
blur=7, | |
threshold=0.4, | |
dilation_factor=4, | |
)[0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment