diff --git a/comfyui_to_python.py b/comfyui_to_python.py index 33e6e53..127bf1e 100644 --- a/comfyui_to_python.py +++ b/comfyui_to_python.py @@ -40,7 +40,7 @@ def read_json_file(file_path: str) -> dict: """ try: - with open(file_path, 'r') as file: + with open(file_path, 'r', encoding='utf-8') as file: data = json.load(file) return data @@ -452,9 +452,9 @@ def execute(self): if __name__ == '__main__': # Update class parameters here - input_file = 'workflow_api.json' - output_file = 'workflow_api.py' - queue_size = 10 + input_file = 'image_text_matting_api.json' + output_file = 'image_text_matting_api.py' + queue_size = 1 # Convert ComfyUI workflow to Python ComfyUItoPython(input_file=input_file, output_file=output_file, queue_size=queue_size) diff --git a/dianshang_v2.json b/dianshang_v2.json new file mode 100644 index 0000000..5823ca6 --- /dev/null +++ b/dianshang_v2.json @@ -0,0 +1,1812 @@ +{ + "last_node_id": 105, + "last_link_id": 174, + "nodes": [ + { + "id": 29, + "type": "GroundingDinoSAMSegment (segment anything)", + "pos": [ + -961.222774929441, + 217.5553351508252 + ], + "size": { + "0": 352.79998779296875, + "1": 124.0001220703125 + }, + "flags": {}, + "order": 16, + "mode": 0, + "inputs": [ + { + "name": "sam_model", + "type": "SAM_MODEL", + "link": 55, + "label": "SAM模型" + }, + { + "name": "grounding_dino_model", + "type": "GROUNDING_DINO_MODEL", + "link": 56, + "label": "G-Dino模型" + }, + { + "name": "image", + "type": "IMAGE", + "link": 165, + "label": "图像" + } + ], + "outputs": [ + { + "name": "IMAGE", + "type": "IMAGE", + "links": [], + "shape": 3, + "slot_index": 0, + "label": " 图像" + }, + { + "name": "MASK", + "type": "MASK", + "links": [ + 59, + 111 + ], + "shape": 3, + "slot_index": 1, + "label": "遮罩" + } + ], + "properties": { + "Node name for S&R": "GroundingDinoSAMSegment (segment anything)" + }, + "widgets_values": [ + "瓶子", + 0.3 + ], + "_widget_cache_map": {}, + "category": "Custom Nodes" + }, + { + "id": 47, + "type": "CheckpointLoaderSimple", + "pos": [ + -827, + -540 + ], + "size": { + "0": 481, + "1": 158 + }, + "flags": {}, + "order": 0, + "mode": 0, + "outputs": [ + { + "name": "MODEL", + "type": "MODEL", + "links": [ + 82 + ], + "shape": 3, + "slot_index": 0, + "label": "模型" + }, + { + "name": "CLIP", + "type": "CLIP", + "links": [ + 83 + ], + "shape": 3, + "slot_index": 1, + "label": "CLIP" + }, + { + "name": "VAE", + "type": "VAE", + "links": [ + 98, + 109 + ], + "shape": 3, + "slot_index": 2, + "label": "VAE" + } + ], + "properties": { + "Node name for S&R": "CheckpointLoaderSimple" + }, + "widgets_values": [ + "realisticVision V6.0 B1_V6.0 B1" + ], + "_widget_cache_map": { + "realisticVision V6.0 B1_V6.0 B1": { + "name": "realisticVision V6.0 B1_V6.0 B1", + "value": 575082 + } + }, + "category": "Primitive Nodes" + }, + { + "id": 82, + "type": "LoraLoader", + "pos": [ + -810, + -995 + ], + "size": [ + 455.26606465351097, + 191.115824546589 + ], + "flags": {}, + "order": 15, + "mode": 0, + "inputs": [ + { + "name": "model", + "type": "MODEL", + "link": 151, + "label": "模型" + }, + { + "name": "clip", + "type": "CLIP", + "link": 153, + "label": "CLIP" + } + ], + "outputs": [ + { + "name": "MODEL", + "type": "MODEL", + "links": [ + 152 + ], + "shape": 3, + "slot_index": 0, + "label": "模型" + }, + { + "name": "CLIP", + "type": "CLIP", + "links": [ + 154, + 155 + ], + "shape": 3, + "slot_index": 1, + "label": "CLIP" + } + ], + "properties": { + "Node name for S&R": "LoraLoader" + }, + "widgets_values": [ + "万物调节丨质感增强器_V1.0", + 0.2, + 1 + ], + "_widget_cache_map": { + "万物调节丨质感增强器_V1.0": { + "name": "万物调节丨质感增强器_V1.0", + "value": 1800476 + } + }, + "category": "Primitive Nodes" + }, + { + "id": 67, + "type": "BNK_CLIPTextEncodeAdvanced", + "pos": [ + -342, + -748 + ], + "size": { + "0": 400, + "1": 200 + }, + "flags": {}, + "order": 19, + "mode": 0, + "inputs": [ + { + "name": "clip", + "type": "CLIP", + "link": 155, + "label": "CLIP" + } + ], + "outputs": [ + { + "name": "CONDITIONING", + "type": "CONDITIONING", + "links": [ + 157 + ], + "shape": 3, + "label": "条件" + } + ], + "properties": { + "Node name for S&R": "BNK_CLIPTextEncodeAdvanced" + }, + "widgets_values": [ + "easynegative, (worst quality:1.4), (low quality:1.4), (normal quality:1.4),", + "none", + "A1111" + ], + "_widget_cache_map": {}, + "color": "#322", + "bgcolor": "#533", + "category": "Custom Nodes" + }, + { + "id": 86, + "type": "Note", + "pos": [ + -282, + -1144 + ], + "size": { + "0": 243.3450164794922, + "1": 109.30449676513672 + }, + "flags": {}, + "order": 1, + "mode": 0, + "properties": { + "text": "" + }, + "widgets_values": [ + "提示词一定要写好,可以加入 水、石头、花等提示词" + ], + "_widget_cache_map": {}, + "color": "#432", + "bgcolor": "#653", + "category": "Official" + }, + { + "id": 90, + "type": "ControlNetLoader", + "pos": [ + 90.55555640327115, + -594.6664632161466 + ], + "size": [ + 455.30133785927467, + 67.0833761006545 + ], + "flags": {}, + "order": 2, + "mode": 0, + "outputs": [ + { + "name": "CONTROL_NET", + "type": "CONTROL_NET", + "links": [ + 162 + ], + "shape": 3, + "label": "ControlNet" + } + ], + "properties": { + "Node name for S&R": "ControlNetLoader" + }, + "widgets_values": [ + "control_v11p_sd15_lineart" + ], + "_widget_cache_map": {}, + "category": "Primitive Nodes" + }, + { + "id": 28, + "type": "SAMModelLoader (segment anything)", + "pos": [ + -961.222774929441, + 117.55533515082512 + ], + "size": [ + 354.7147773720749, + 58 + ], + "flags": {}, + "order": 3, + "mode": 0, + "outputs": [ + { + "name": "SAM_MODEL", + "type": "SAM_MODEL", + "links": [ + 55 + ], + "shape": 3, + "slot_index": 0, + "label": "SAM模型" + } + ], + "properties": { + "Node name for S&R": "SAMModelLoader (segment anything)" + }, + "widgets_values": [ + "sam_vit_h_4b8939.pth" + ], + "_widget_cache_map": {}, + "category": "Custom Nodes" + }, + { + "id": 27, + "type": "GroundingDinoModelLoader (segment anything)", + "pos": [ + -961.222774929441, + -22.444664849174856 + ], + "size": [ + 355.5742001796814, + 100.72856731307937 + ], + "flags": {}, + "order": 4, + "mode": 0, + "outputs": [ + { + "name": "GROUNDING_DINO_MODEL", + "type": "GROUNDING_DINO_MODEL", + "links": [ + 56 + ], + "shape": 3, + "slot_index": 0, + "label": "G-Dino模型" + } + ], + "properties": { + "Node name for S&R": "GroundingDinoModelLoader (segment anything)" + }, + "widgets_values": [ + "GroundingDINO_SwinT_OGC (694MB)" + ], + "_widget_cache_map": {}, + "category": "Custom Nodes" + }, + { + "id": 58, + "type": "InvertMask", + "pos": [ + -961.222774929441, + -82.44466484917477 + ], + "size": [ + 348.1358530647558, + 30.77178119666405 + ], + "flags": {}, + "order": 21, + "mode": 0, + "inputs": [ + { + "name": "mask", + "type": "MASK", + "link": 111, + "label": "遮罩" + } + ], + "outputs": [ + { + "name": "MASK", + "type": "MASK", + "links": [ + 112 + ], + "shape": 3, + "label": "遮罩", + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "InvertMask" + }, + "category": "Custom Nodes" + }, + { + "id": 31, + "type": "MaskToImage", + "pos": [ + -961.222774929441, + -152.44466484917487 + ], + "size": [ + 338.86392050860286, + 26 + ], + "flags": {}, + "order": 20, + "mode": 0, + "inputs": [ + { + "name": "mask", + "type": "MASK", + "link": 59, + "label": "遮罩" + } + ], + "outputs": [ + { + "name": "IMAGE", + "type": "IMAGE", + "links": [ + 60 + ], + "shape": 3, + "slot_index": 0, + "label": "图像" + } + ], + "properties": { + "Node name for S&R": "MaskToImage" + }, + "category": "Custom Nodes" + }, + { + "id": 85, + "type": "Note", + "pos": [ + -881.2227749294411, + 387.55533515082476 + ], + "size": { + "0": 210, + "1": 58 + }, + "flags": {}, + "order": 5, + "mode": 0, + "properties": { + "text": "" + }, + "widgets_values": [ + "提示词写你的产品图" + ], + "_widget_cache_map": {}, + "color": "#432", + "bgcolor": "#653", + "category": "Official" + }, + { + "id": 83, + "type": "Note", + "pos": [ + -1036, + -955 + ], + "size": { + "0": 210, + "1": 84.87100219726562 + }, + "flags": {}, + "order": 6, + "mode": 0, + "properties": { + "text": "" + }, + "widgets_values": [ + "\n\n触发提示词Picture enhancement" + ], + "_widget_cache_map": {}, + "color": "#432", + "bgcolor": "#653", + "category": "Official" + }, + { + "id": 32, + "type": "PreviewImage", + "pos": [ + -601.222774929442, + -142.44466484917484 + ], + "size": [ + 223.21490368733657, + 472.1228266556848 + ], + "flags": {}, + "order": 24, + "mode": 0, + "inputs": [ + { + "name": "images", + "type": "IMAGE", + "link": 60, + "label": "图像" + } + ], + "properties": { + "Node name for S&R": "PreviewImage" + }, + "category": "Primitive Nodes" + }, + { + "id": 87, + "type": "ControlNetApplyAdvanced", + "pos": [ + 84.55555640327117, + -939.6664632161466 + ], + "size": [ + 458.1931534160045, + 173.4384623175947 + ], + "flags": {}, + "order": 23, + "mode": 0, + "inputs": [ + { + "name": "positive", + "type": "CONDITIONING", + "link": 156, + "label": "正面条件", + "slot_index": 0 + }, + { + "name": "negative", + "type": "CONDITIONING", + "link": 157, + "label": "负面条件", + "slot_index": 1 + }, + { + "name": "control_net", + "type": "CONTROL_NET", + "link": 162, + "label": "ControlNet", + "slot_index": 2 + }, + { + "name": "image", + "type": "IMAGE", + "link": 160, + "label": "图像" + } + ], + "outputs": [ + { + "name": "positive", + "type": "CONDITIONING", + "links": [ + 158 + ], + "shape": 3, + "label": "正面条件", + "slot_index": 0 + }, + { + "name": "negative", + "type": "CONDITIONING", + "links": [ + 159 + ], + "shape": 3, + "label": "负面条件", + "slot_index": 1 + } + ], + "properties": { + "Node name for S&R": "ControlNetApplyAdvanced" + }, + "widgets_values": [ + 1, + 0, + 1 + ], + "_widget_cache_map": {}, + "category": "Primitive Nodes" + }, + { + "id": 74, + "type": "CR Latent Batch Size", + "pos": [ + -270, + 130 + ], + "size": { + "0": 315, + "1": 58 + }, + "flags": {}, + "order": 26, + "mode": 0, + "inputs": [ + { + "name": "latent", + "type": "LATENT", + "link": 139, + "label": "Latent", + "slot_index": 0 + } + ], + "outputs": [ + { + "name": "LATENT", + "type": "LATENT", + "links": [ + 140 + ], + "shape": 3, + "label": "Latent", + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "CR Latent Batch Size" + }, + "widgets_values": [ + 4 + ], + "_widget_cache_map": {}, + "category": "Custom Nodes" + }, + { + "id": 56, + "type": "KSampler", + "pos": [ + -280, + 220 + ], + "size": { + "0": 315, + "1": 262 + }, + "flags": {}, + "order": 27, + "mode": 0, + "inputs": [ + { + "name": "model", + "type": "MODEL", + "link": 104, + "label": "模型" + }, + { + "name": "positive", + "type": "CONDITIONING", + "link": 105, + "label": "正面条件" + }, + { + "name": "negative", + "type": "CONDITIONING", + "link": 106, + "label": "负面条件" + }, + { + "name": "latent_image", + "type": "LATENT", + "link": 140, + "label": "Latent", + "slot_index": 3 + } + ], + "outputs": [ + { + "name": "LATENT", + "type": "LATENT", + "links": [ + 128 + ], + "shape": 3, + "label": "Latent", + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "KSampler" + }, + "widgets_values": [ + 789798, + "randomize", + 25, + 7.5, + "dpmpp_2m", + "karras", + 1 + ], + "_widget_cache_map": {}, + "category": "Primitive Nodes" + }, + { + "id": 55, + "type": "BrushNet", + "pos": [ + -270, + -130 + ], + "size": { + "0": 315, + "1": 226 + }, + "flags": {}, + "order": 25, + "mode": 0, + "inputs": [ + { + "name": "model", + "type": "MODEL", + "link": 152, + "label": "模型" + }, + { + "name": "vae", + "type": "VAE", + "link": 98, + "label": "VAE", + "slot_index": 1 + }, + { + "name": "image", + "type": "IMAGE", + "link": 167, + "label": "图像", + "slot_index": 2 + }, + { + "name": "mask", + "type": "MASK", + "link": 112, + "label": "遮罩" + }, + { + "name": "brushnet", + "type": "BRMODEL", + "link": 101, + "label": "BrushNet", + "slot_index": 4 + }, + { + "name": "positive", + "type": "CONDITIONING", + "link": 158, + "label": "正面条件", + "slot_index": 5 + }, + { + "name": "negative", + "type": "CONDITIONING", + "link": 159, + "label": "负面条件", + "slot_index": 6 + } + ], + "outputs": [ + { + "name": "model", + "type": "MODEL", + "links": [ + 104 + ], + "shape": 3, + "label": "模型", + "slot_index": 0 + }, + { + "name": "positive", + "type": "CONDITIONING", + "links": [ + 105 + ], + "shape": 3, + "label": "正面条件", + "slot_index": 1 + }, + { + "name": "negative", + "type": "CONDITIONING", + "links": [ + 106 + ], + "shape": 3, + "label": "负面条件", + "slot_index": 2 + }, + { + "name": "latent", + "type": "LATENT", + "links": [ + 139 + ], + "shape": 3, + "label": "Latent", + "slot_index": 3 + } + ], + "properties": { + "Node name for S&R": "BrushNet" + }, + "widgets_values": [ + 1, + 0, + 10000 + ], + "_widget_cache_map": {}, + "category": "Custom Nodes" + }, + { + "id": 45, + "type": "BrushNetLoader", + "pos": [ + -270, + -270 + ], + "size": [ + 308.5988490840116, + 109.39274774943942 + ], + "flags": {}, + "order": 7, + "mode": 0, + "outputs": [ + { + "name": "brushnet", + "type": "BRMODEL", + "links": [ + 101 + ], + "shape": 3, + "slot_index": 0, + "label": "BrushNet" + } + ], + "properties": { + "Node name for S&R": "BrushNetLoader" + }, + "widgets_values": [ + "segmentation_mask_brushnet_ckpt.safetensors", + "float16" + ], + "_widget_cache_map": {}, + "category": "Custom Nodes" + }, + { + "id": 97, + "type": "ConstrainImage|pysssss", + "pos": [ + -1475, + -748 + ], + "size": { + "0": 315, + "1": 154 + }, + "flags": {}, + "order": 14, + "mode": 0, + "inputs": [ + { + "name": "images", + "type": "IMAGE", + "link": 164, + "label": "图像", + "slot_index": 0 + } + ], + "outputs": [ + { + "name": "IMAGE", + "type": "IMAGE", + "links": [ + 165, + 166, + 167 + ], + "shape": 6, + "label": "图像", + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "ConstrainImage|pysssss" + }, + "widgets_values": [ + 1024, + 1024, + 0, + 0, + "no" + ], + "_widget_cache_map": {}, + "category": "Custom Nodes" + }, + { + "id": 98, + "type": "Note", + "pos": [ + -1464, + -544 + ], + "size": [ + 299.9174826079902, + 74.9001910743354 + ], + "flags": {}, + "order": 8, + "mode": 0, + "properties": { + "text": "" + }, + "widgets_values": [ + "此节点的目的是为了降低图片的大小(不是尺寸大小),图像太大的话跑起来会很慢 偶尔还会报错,所以弄了这么一个节点,有些是电商厂家实拍的商品几十MB。" + ], + "_widget_cache_map": {}, + "color": "#432", + "bgcolor": "#653", + "category": "Official" + }, + { + "id": 57, + "type": "VAEDecode", + "pos": [ + -270, + 520 + ], + "size": [ + 293.7051433197066, + 46 + ], + "flags": {}, + "order": 28, + "mode": 0, + "inputs": [ + { + "name": "samples", + "type": "LATENT", + "link": 128, + "label": "Latent" + }, + { + "name": "vae", + "type": "VAE", + "link": 109, + "label": "VAE" + } + ], + "outputs": [ + { + "name": "IMAGE", + "type": "IMAGE", + "links": [ + 163, + 172 + ], + "shape": 3, + "label": "图像", + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "VAEDecode" + }, + "category": "Primitive Nodes" + }, + { + "id": 99, + "type": "Note", + "pos": [ + -1106, + -801 + ], + "size": [ + 260.84769593042984, + 398.0250789078807 + ], + "flags": {}, + "order": 9, + "mode": 0, + "properties": { + "text": "" + }, + "widgets_values": [ + "这边的模型可以更换自己喜欢的类型,\n\n注意: 如果你更换了XL的模型 后面所有的模型必须换XL的 \n\n包括ControlNet\n\n\n工作流默认是1.5的模型" + ], + "_widget_cache_map": {}, + "color": "#432", + "bgcolor": "#653", + "category": "Official" + }, + { + "id": 51, + "type": "LoraLoader", + "pos": [ + -817, + -766 + ], + "size": [ + 468.4861630563073, + 189.14941624865423 + ], + "flags": {}, + "order": 13, + "mode": 0, + "inputs": [ + { + "name": "model", + "type": "MODEL", + "link": 82, + "label": "模型" + }, + { + "name": "clip", + "type": "CLIP", + "link": 83, + "label": "CLIP" + } + ], + "outputs": [ + { + "name": "MODEL", + "type": "MODEL", + "links": [ + 151 + ], + "shape": 3, + "slot_index": 0, + "label": "模型" + }, + { + "name": "CLIP", + "type": "CLIP", + "links": [ + 153 + ], + "shape": 3, + "slot_index": 1, + "label": "CLIP" + } + ], + "properties": { + "Node name for S&R": "LoraLoader" + }, + "widgets_values": [ + "电商展台多场景3.0_电商展台-V1", + 0.75, + 1 + ], + "_widget_cache_map": { + "自然美妆场景_2.0": { + "name": "自然美妆场景_2.0", + "value": 1486402 + }, + "电商展台多场景3.0_电商展台-V1": { + "name": "电商展台多场景3.0_电商展台-V1", + "value": 1449688 + } + }, + "category": "Primitive Nodes" + }, + { + "id": 101, + "type": "DetailTransfer", + "pos": [ + -270, + -450 + ], + "size": { + "0": 315, + "1": 146 + }, + "flags": {}, + "order": 30, + "mode": 0, + "inputs": [ + { + "name": "target", + "type": "IMAGE", + "link": 172, + "label": "目标图像", + "slot_index": 0 + }, + { + "name": "source", + "type": "IMAGE", + "link": 171, + "label": "参考图像", + "slot_index": 1 + }, + { + "name": "mask", + "type": "MASK", + "link": null, + "label": "遮罩" + } + ], + "outputs": [ + { + "name": "IMAGE", + "type": "IMAGE", + "links": [ + 170 + ], + "shape": 3, + "label": "图像", + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "DetailTransfer" + }, + "widgets_values": [ + "add", + 1, + 1 + ], + "_widget_cache_map": {}, + "category": "Custom Nodes" + }, + { + "id": 89, + "type": "LineArtPreprocessor", + "pos": [ + 90.55555640327115, + -726.6664632161466 + ], + "size": [ + 450.7399323638907, + 89.60964421143967 + ], + "flags": {}, + "order": 17, + "mode": 0, + "inputs": [ + { + "name": "image", + "type": "IMAGE", + "link": 166, + "label": "图像", + "slot_index": 0 + } + ], + "outputs": [ + { + "name": "IMAGE", + "type": "IMAGE", + "links": [ + 160, + 174 + ], + "shape": 3, + "label": "图像", + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "LineArtPreprocessor" + }, + "widgets_values": [ + "disable", + 512 + ], + "_widget_cache_map": {}, + "category": "Custom Nodes" + }, + { + "id": 91, + "type": "PreviewImage", + "pos": [ + 99, + 179 + ], + "size": [ + 285.6074740991744, + 336.4753371663163 + ], + "flags": {}, + "order": 29, + "mode": 0, + "inputs": [ + { + "name": "images", + "type": "IMAGE", + "link": 163, + "label": "图像" + } + ], + "properties": { + "Node name for S&R": "PreviewImage" + }, + "category": "Primitive Nodes" + }, + { + "id": 1, + "type": "LoadImage", + "pos": [ + -2357, + -847 + ], + "size": [ + 861.3813347199493, + 961.8630470429935 + ], + "flags": {}, + "order": 10, + "mode": 0, + "outputs": [ + { + "name": "IMAGE", + "type": "IMAGE", + "links": [ + 164, + 171 + ], + "shape": 3, + "slot_index": 0, + "label": "图像" + }, + { + "name": "MASK", + "type": "MASK", + "links": null, + "shape": 3, + "slot_index": 1, + "label": "遮罩" + } + ], + "properties": { + "Node name for S&R": "LoadImage" + }, + "widgets_values": [ + "抠图后.png", + "image" + ], + "_widget_cache_map": { + "9407109949768fb876816d0c951d8eb2915a79814017dab2375446c7dc091a57.png": { + "value": "img/46987de339ac47e0965172f7ccd1b939/9407109949768fb876816d0c951d8eb2915a79814017dab2375446c7dc091a57.png", + "name": "9407109949768fb876816d0c951d8eb2915a79814017dab2375446c7dc091a57.png", + "url": "https://liblibai-tmp-image.vibrou.com/img/46987de339ac47e0965172f7ccd1b939/9407109949768fb876816d0c951d8eb2915a79814017dab2375446c7dc091a57.png" + }, + "微信图片_20240726215528.png": { + "value": "img/46987de339ac47e0965172f7ccd1b939/2bcc41b8f01a6ece719d80ddf01bfe676164b63bb9edd6610e93a373f45ac5d7.png", + "name": "微信图片_20240726215528.png", + "url": "https://liblibai-tmp-image.vibrou.com/img/46987de339ac47e0965172f7ccd1b939/2bcc41b8f01a6ece719d80ddf01bfe676164b63bb9edd6610e93a373f45ac5d7.png" + }, + "透明底图123.png": { + "value": "img/46987de339ac47e0965172f7ccd1b939/832be2b7279c6512bb0a729d9c1a0e28aa05019dad5e82d9d7bed8b5afffd51a.png", + "name": "透明底图123.png", + "url": "https://liblibai-tmp-image.vibrou.com/img/46987de339ac47e0965172f7ccd1b939/832be2b7279c6512bb0a729d9c1a0e28aa05019dad5e82d9d7bed8b5afffd51a.png" + }, + "透明.png": { + "value": "img/46987de339ac47e0965172f7ccd1b939/8c8b2350db23ee534972ddee3adba7a1cbd3aaa5052e6da7445a980de2b13452.png", + "name": "透明.png", + "url": "https://liblibai-tmp-image.vibrou.com/img/46987de339ac47e0965172f7ccd1b939/8c8b2350db23ee534972ddee3adba7a1cbd3aaa5052e6da7445a980de2b13452.png" + }, + "cef6e0f2d2d2ebc25c367d8dc70c4c31149d7df536a3e3960b9b91dc46a6e17d.png": { + "value": "img/46987de339ac47e0965172f7ccd1b939/cef6e0f2d2d2ebc25c367d8dc70c4c31149d7df536a3e3960b9b91dc46a6e17d.png", + "name": "cef6e0f2d2d2ebc25c367d8dc70c4c31149d7df536a3e3960b9b91dc46a6e17d.png", + "url": "https://liblibai-tmp-image.vibrou.com/img/46987de339ac47e0965172f7ccd1b939/cef6e0f2d2d2ebc25c367d8dc70c4c31149d7df536a3e3960b9b91dc46a6e17d.png" + }, + "1+1.jpg": { + "value": "img/46987de339ac47e0965172f7ccd1b939/7ed2f75e7b95c72c0fb34f9d064c3837d3c2df4724bbc7a86122e3ad7d6bd451.jpg", + "name": "1+1.jpg", + "url": "https://liblibai-tmp-image.vibrou.com/img/46987de339ac47e0965172f7ccd1b939/7ed2f75e7b95c72c0fb34f9d064c3837d3c2df4724bbc7a86122e3ad7d6bd451.jpg" + }, + "抠图后.png": { + "value": "img/46987de339ac47e0965172f7ccd1b939/bdcf57370fabfc8d54058b067d319de0a2c9ee038d8af7f4cfddda441242c1fa.png", + "name": "抠图后.png", + "url": "https://liblibai-tmp-image.vibrou.com/img/46987de339ac47e0965172f7ccd1b939/bdcf57370fabfc8d54058b067d319de0a2c9ee038d8af7f4cfddda441242c1fa.png" + } + }, + "category": "Primitive Nodes" + }, + { + "id": 66, + "type": "BNK_CLIPTextEncodeAdvanced", + "pos": [ + -343, + -991 + ], + "size": { + "0": 400, + "1": 200 + }, + "flags": {}, + "order": 18, + "mode": 0, + "inputs": [ + { + "name": "clip", + "type": "CLIP", + "link": 154, + "label": "CLIP" + } + ], + "outputs": [ + { + "name": "CONDITIONING", + "type": "CONDITIONING", + "links": [ + 156 + ], + "shape": 3, + "label": "条件" + } + ], + "properties": { + "Node name for S&R": "BNK_CLIPTextEncodeAdvanced" + }, + "widgets_values": [ + "Picture enhancement, close-up, White flowers, white daffodils, blurred background, gray background, Blurred Foreground, simple solid background, plants, trees, center composition, Depth of field , Cosmetic,exhibit booth", + "none", + "A1111" + ], + "_widget_cache_map": {}, + "color": "#232", + "bgcolor": "#353", + "category": "Custom Nodes" + }, + { + "id": 104, + "type": "PreviewImage", + "pos": [ + 102, + -486 + ], + "size": [ + 524.9711369470238, + 447.31599171685434 + ], + "flags": {}, + "order": 22, + "mode": 0, + "inputs": [ + { + "name": "images", + "type": "IMAGE", + "link": 174, + "label": "图像" + } + ], + "properties": { + "Node name for S&R": "PreviewImage" + }, + "category": "Primitive Nodes" + }, + { + "id": 100, + "type": "Note", + "pos": [ + 72, + 593 + ], + "size": [ + 565.9133113775629, + 109.77243153740864 + ], + "flags": {}, + "order": 11, + "mode": 0, + "properties": { + "text": "" + }, + "widgets_values": [ + "高清无损修复地址 :https://www.liblib.art/modelinfo/a783762169f64cbfb1f38280e89b4472?from=personal_page\n\n1.0版本的通过模型放大移除了 ,这次2.0版本采用高清无损放大\n\n" + ], + "_widget_cache_map": {}, + "color": "#432", + "bgcolor": "#653", + "category": "Official" + }, + { + "id": 102, + "type": "PreviewImage", + "pos": [ + 760, + -977 + ], + "size": [ + 2974.4992871610343, + 2185.161523510271 + ], + "flags": {}, + "order": 31, + "mode": 0, + "inputs": [ + { + "name": "images", + "type": "IMAGE", + "link": 170, + "label": "图像" + } + ], + "properties": { + "Node name for S&R": "PreviewImage" + }, + "category": "Primitive Nodes" + }, + { + "id": 84, + "type": "Note", + "pos": [ + -1311, + -1527 + ], + "size": [ + 551.9970995806987, + 451.3134130213739 + ], + "flags": {}, + "order": 12, + "mode": 0, + "properties": { + "text": "" + }, + "widgets_values": [ + "简单说一下这个工作流\n\n\n\n核心是用BrushNet重绘产品背景,出图效果非常奈斯。\n\n\n\n对于新手而言相对较好,只需要修改提示词、LORA、和语义分割\n\n\n\n这次的内置节点不是很多,G-DinoSAM语义分割会先抠出产品图,但有时候抠出的产品偶尔会不行,\n\n一键抠图地址:\nhttps://www.liblib.art/modelinfo/9c298d00c4eb4c7c92b6d8c582352e58?from=personal_page\n\n\n\n我的建议是先单独复制一份这个G-DinoSAM语义分割和放大,抠出一个满意的图后再导入这个工作流,这样原图质量就提升了,后续的流程以及出图质量会更好。\n\n导入产品最好是透明底图\n不是白底图\n\n产品图不能占画面太多,留点空间让AI来换背景,但也不能留太多,留太多会造成产品模糊 换出来的效果不佳\n\n\n遇到问题请即使反馈给我,我会通过大家的问题来一一排除 查找解决方法,因为每个人的产品图不一样,每个人的使用场景不一样,所以 我需要大家的反馈效果这样才能更好的做出V3版本。" + ], + "_widget_cache_map": {}, + "color": "#432", + "bgcolor": "#653", + "category": "Official" + } + ], + "links": [ + [ + 55, + 28, + 0, + 29, + 0, + "SAM_MODEL" + ], + [ + 56, + 27, + 0, + 29, + 1, + "GROUNDING_DINO_MODEL" + ], + [ + 59, + 29, + 1, + 31, + 0, + "MASK" + ], + [ + 60, + 31, + 0, + 32, + 0, + "IMAGE" + ], + [ + 82, + 47, + 0, + 51, + 0, + "MODEL" + ], + [ + 83, + 47, + 1, + 51, + 1, + "CLIP" + ], + [ + 98, + 47, + 2, + 55, + 1, + "VAE" + ], + [ + 101, + 45, + 0, + 55, + 4, + "BRMODEL" + ], + [ + 104, + 55, + 0, + 56, + 0, + "MODEL" + ], + [ + 105, + 55, + 1, + 56, + 1, + "CONDITIONING" + ], + [ + 106, + 55, + 2, + 56, + 2, + "CONDITIONING" + ], + [ + 109, + 47, + 2, + 57, + 1, + "VAE" + ], + [ + 111, + 29, + 1, + 58, + 0, + "MASK" + ], + [ + 112, + 58, + 0, + 55, + 3, + "MASK" + ], + [ + 128, + 56, + 0, + 57, + 0, + "LATENT" + ], + [ + 139, + 55, + 3, + 74, + 0, + "LATENT" + ], + [ + 140, + 74, + 0, + 56, + 3, + "LATENT" + ], + [ + 151, + 51, + 0, + 82, + 0, + "MODEL" + ], + [ + 152, + 82, + 0, + 55, + 0, + "MODEL" + ], + [ + 153, + 51, + 1, + 82, + 1, + "CLIP" + ], + [ + 154, + 82, + 1, + 66, + 0, + "CLIP" + ], + [ + 155, + 82, + 1, + 67, + 0, + "CLIP" + ], + [ + 156, + 66, + 0, + 87, + 0, + "CONDITIONING" + ], + [ + 157, + 67, + 0, + 87, + 1, + "CONDITIONING" + ], + [ + 158, + 87, + 0, + 55, + 5, + "CONDITIONING" + ], + [ + 159, + 87, + 1, + 55, + 6, + "CONDITIONING" + ], + [ + 160, + 89, + 0, + 87, + 3, + "IMAGE" + ], + [ + 162, + 90, + 0, + 87, + 2, + "CONTROL_NET" + ], + [ + 163, + 57, + 0, + 91, + 0, + "IMAGE" + ], + [ + 164, + 1, + 0, + 97, + 0, + "IMAGE" + ], + [ + 165, + 97, + 0, + 29, + 2, + "IMAGE" + ], + [ + 166, + 97, + 0, + 89, + 0, + "IMAGE" + ], + [ + 167, + 97, + 0, + 55, + 2, + "IMAGE" + ], + [ + 170, + 101, + 0, + 102, + 0, + "IMAGE" + ], + [ + 171, + 1, + 0, + 101, + 1, + "IMAGE" + ], + [ + 172, + 57, + 0, + 101, + 0, + "IMAGE" + ], + [ + 174, + 89, + 0, + 104, + 0, + "IMAGE" + ] + ], + "groups": [ + { + "title": "抠图区组件", + "bounding": [ + -1100, + -351, + 760, + 824 + ], + "color": "#3f789e", + "font_size": 100, + "locked": false + }, + { + "title": "ControlNet控制组件", + "bounding": [ + 84, + -1060, + 579, + 1037 + ], + "color": "#3f789e", + "font_size": 60, + "locked": false + }, + { + "title": "产品图导入", + "bounding": [ + -2380, + -1096, + 893, + 1224 + ], + "color": "#3f789e", + "font_size": 150, + "locked": false + }, + { + "title": "最终出图", + "bounding": [ + 741, + -1288, + 3029, + 2508 + ], + "color": "#3f789e", + "font_size": 200, + "locked": false + } + ], + "config": {}, + "extra": { + "ds": { + "scale": 0.69343349494416, + "offset": [ + 1929.2614099987882, + 1639.062002958689 + ] + }, + "0246.VERSION": [ + 0, + 0, + 4 + ] + }, + "version": 0.4 +} \ No newline at end of file diff --git a/ds_off.json b/ds_off.json new file mode 100644 index 0000000..5ad021d --- /dev/null +++ b/ds_off.json @@ -0,0 +1,44 @@ +{ + "13": { + "inputs": { + "model": "Qwen/Qwen1.5-0.5B-Chat", + "device": "cuda", + "low_memory": true + }, + "class_type": "LoadText2PromptModel", + "_meta": { + "title": "Loader Text to Prompt Model 🐼" + } + }, + "14": { + "inputs": { + "prompt": "Exquisite,many details,night scene,dream,moon,meteor,far away", + "max_tokens": 128, + "temperature": 0.2, + "print_output": "disable", + "cached": "NO", + "prefix": "must be in english and describe a picture according to follow the description below within 77 words: ", + "system_prompt": "You are a helpful assistant.", + "model": [ + "13", + 0 + ] + }, + "class_type": "Text2Prompt", + "_meta": { + "title": "Text to Prompt 🐼" + } + }, + "18": { + "inputs": { + "text": [ + "14", + 0 + ] + }, + "class_type": "ShowText|fofo", + "_meta": { + "title": "Show Text 🐼" + } + } +} \ No newline at end of file diff --git a/ds_off_noapi.json b/ds_off_noapi.json new file mode 100644 index 0000000..0906859 --- /dev/null +++ b/ds_off_noapi.json @@ -0,0 +1,1056 @@ +{ + "last_node_id": 58, + "last_link_id": 59, + "nodes": [ + { + "id": 5, + "type": "EmptyLatentImage", + "pos": [ + 485, + 803 + ], + "size": { + "0": 315, + "1": 106 + }, + "flags": {}, + "order": 0, + "mode": 2, + "outputs": [ + { + "name": "LATENT", + "type": "LATENT", + "links": [ + 2 + ], + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "EmptyLatentImage" + }, + "widgets_values": [ + 512, + 768, + 1 + ] + }, + { + "id": 13, + "type": "LoadText2PromptModel", + "pos": [ + -569.5084608154301, + -769.8625924224857 + ], + "size": { + "0": 315, + "1": 106 + }, + "flags": { + "collapsed": false + }, + "order": 1, + "mode": 0, + "outputs": [ + { + "name": "TEXT2PROMPT_MODEL", + "type": "TEXT2PROMPT_MODEL", + "links": [ + 11 + ], + "shape": 3, + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "LoadText2PromptModel" + }, + "widgets_values": [ + "Qwen/Qwen1.5-0.5B-Chat", + "cuda", + true + ] + }, + { + "id": 50, + "type": "TextBox|fofo", + "pos": [ + -72.89598327636722, + -375.8880020904541 + ], + "size": { + "0": 400, + "1": 200 + }, + "flags": {}, + "order": 2, + "mode": 2, + "outputs": [ + { + "name": "STRING", + "type": "STRING", + "links": [ + 48 + ], + "shape": 3, + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "TextBox|fofo" + }, + "widgets_values": [ + "A small ship sails through the vast blue expanse of the ocean, its sails billowing with the wind as it navigates through the vast expanse of the sky. In the distance, a larus flutters across the water, its wings spread wide and powerful, and it glides effortlessly through the air. The stars twinkle overhead, casting long shadows on the water, creating a mesmerizing display of light and color. As the ship approaches the shore, it is illuminated by the stars, making it seem like it's floating in a dreamy world." + ] + }, + { + "id": 46, + "type": "CLIPTextEncode", + "pos": [ + 510.1040167236328, + 244.111997909546 + ], + "size": { + "0": 355.5054626464844, + "1": 57.71168899536133 + }, + "flags": {}, + "order": 12, + "mode": 2, + "inputs": [ + { + "name": "clip", + "type": "CLIP", + "link": 43, + "slot_index": 0 + }, + { + "name": "text", + "type": "STRING", + "link": 48, + "widget": { + "name": "text" + }, + "slot_index": 1 + } + ], + "outputs": [ + { + "name": "CONDITIONING", + "type": "CONDITIONING", + "links": [ + 38 + ], + "shape": 3, + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "CLIPTextEncode" + }, + "widgets_values": [ + "A small ship sails through the vast blue expanse of the ocean, its sails billowing with the wind as it navigates through the vast expanse of the sky. In the distance, a larus flutters across the water, its wings spread wide and powerful, and it glides effortlessly through the air. The stars twinkle overhead, casting long shadows on the water, creating a mesmerizing display of light and color. As the ship approaches the shore, it is illuminated by the stars, making it seem like it's floating in a dreamy world." + ] + }, + { + "id": 47, + "type": "VAELoader", + "pos": [ + 577.1040167236331, + 107.11199790954595 + ], + "size": { + "0": 315, + "1": 58 + }, + "flags": {}, + "order": 3, + "mode": 2, + "outputs": [ + { + "name": "VAE", + "type": "VAE", + "links": [ + 40 + ], + "shape": 3, + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "VAELoader" + }, + "widgets_values": [ + "vaeFtMse840000EmaPruned_vae.safetensors" + ] + }, + { + "id": 44, + "type": "UpscaleModelLoader", + "pos": [ + 951, + 776 + ], + "size": { + "0": 315, + "1": 58 + }, + "flags": {}, + "order": 4, + "mode": 2, + "outputs": [ + { + "name": "UPSCALE_MODEL", + "type": "UPSCALE_MODEL", + "links": [ + 34 + ], + "shape": 3 + } + ], + "properties": { + "Node name for S&R": "UpscaleModelLoader" + }, + "widgets_values": [ + "4x-AnimeSharp.pth" + ] + }, + { + "id": 34, + "type": "PreviewImage", + "pos": [ + 1461, + 287 + ], + "size": { + "0": 210, + "1": 246 + }, + "flags": {}, + "order": 18, + "mode": 2, + "inputs": [ + { + "name": "images", + "type": "IMAGE", + "link": 24 + } + ], + "properties": { + "Node name for S&R": "PreviewImage" + } + }, + { + "id": 45, + "type": "PreviewImage", + "pos": [ + 1716, + 285 + ], + "size": { + "0": 210, + "1": 246 + }, + "flags": {}, + "order": 20, + "mode": 2, + "inputs": [ + { + "name": "images", + "type": "IMAGE", + "link": 35 + } + ], + "properties": { + "Node name for S&R": "PreviewImage" + } + }, + { + "id": 3, + "type": "KSampler", + "pos": [ + 895, + 374 + ], + "size": { + "0": 315, + "1": 262 + }, + "flags": {}, + "order": 16, + "mode": 2, + "inputs": [ + { + "name": "model", + "type": "MODEL", + "link": 41, + "slot_index": 0 + }, + { + "name": "positive", + "type": "CONDITIONING", + "link": 38 + }, + { + "name": "negative", + "type": "CONDITIONING", + "link": 6 + }, + { + "name": "latent_image", + "type": "LATENT", + "link": 2 + } + ], + "outputs": [ + { + "name": "LATENT", + "type": "LATENT", + "links": [ + 7 + ], + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "KSampler" + }, + "widgets_values": [ + 1023268540963448, + "randomize", + 30, + 8, + "dpm_adaptive", + "karras", + 0.9500000000000001 + ] + }, + { + "id": 8, + "type": "VAEDecode", + "pos": [ + 1211, + 243 + ], + "size": { + "0": 210, + "1": 46 + }, + "flags": {}, + "order": 17, + "mode": 2, + "inputs": [ + { + "name": "samples", + "type": "LATENT", + "link": 7 + }, + { + "name": "vae", + "type": "VAE", + "link": 40 + } + ], + "outputs": [ + { + "name": "IMAGE", + "type": "IMAGE", + "links": [ + 24, + 33 + ], + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "VAEDecode" + } + }, + { + "id": 42, + "type": "ImageUpscaleWithModel", + "pos": [ + 1332, + 709 + ], + "size": { + "0": 241.79998779296875, + "1": 46 + }, + "flags": {}, + "order": 19, + "mode": 2, + "inputs": [ + { + "name": "upscale_model", + "type": "UPSCALE_MODEL", + "link": 34, + "slot_index": 0 + }, + { + "name": "image", + "type": "IMAGE", + "link": 33 + } + ], + "outputs": [ + { + "name": "IMAGE", + "type": "IMAGE", + "links": [ + 35, + 36 + ], + "shape": 3, + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "ImageUpscaleWithModel" + } + }, + { + "id": 55, + "type": "PreviewImage", + "pos": [ + 1625.3261180229483, + 1166.614138501562 + ], + "size": { + "0": 210, + "1": 246 + }, + "flags": {}, + "order": 15, + "mode": 2, + "inputs": [ + { + "name": "images", + "type": "IMAGE", + "link": 52 + } + ], + "properties": { + "Node name for S&R": "PreviewImage" + } + }, + { + "id": 53, + "type": "ImageUpscaleWithModel", + "pos": [ + 1209.2052320976563, + 1339.6923758062496 + ], + "size": { + "0": 241.79998779296875, + "1": 46 + }, + "flags": {}, + "order": 10, + "mode": 2, + "inputs": [ + { + "name": "upscale_model", + "type": "UPSCALE_MODEL", + "link": 50, + "slot_index": 0 + }, + { + "name": "image", + "type": "IMAGE", + "link": 59 + } + ], + "outputs": [ + { + "name": "IMAGE", + "type": "IMAGE", + "links": [ + 49, + 52 + ], + "shape": 3, + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "ImageUpscaleWithModel" + } + }, + { + "id": 54, + "type": "UpscaleModelLoader", + "pos": [ + 815.2052320976561, + 1227.6923758062496 + ], + "size": { + "0": 315, + "1": 58 + }, + "flags": {}, + "order": 5, + "mode": 2, + "outputs": [ + { + "name": "UPSCALE_MODEL", + "type": "UPSCALE_MODEL", + "links": [ + 50 + ], + "shape": 3 + } + ], + "properties": { + "Node name for S&R": "UpscaleModelLoader" + }, + "widgets_values": [ + "4x-AnimeSharp.pth" + ] + }, + { + "id": 9, + "type": "SaveImage", + "pos": [ + 1705, + 606 + ], + "size": { + "0": 210, + "1": 270 + }, + "flags": {}, + "order": 21, + "mode": 2, + "inputs": [ + { + "name": "images", + "type": "IMAGE", + "link": 36, + "slot_index": 0 + } + ], + "properties": {}, + "widgets_values": [ + "ComfyUI" + ] + }, + { + "id": 52, + "type": "SaveImage", + "pos": [ + 1651.2052320976563, + 1473.6923758062496 + ], + "size": { + "0": 210, + "1": 270 + }, + "flags": {}, + "order": 14, + "mode": 2, + "inputs": [ + { + "name": "images", + "type": "IMAGE", + "link": 49, + "slot_index": 0 + } + ], + "properties": {}, + "widgets_values": [ + "ComfyUI" + ] + }, + { + "id": 48, + "type": "LoraLoader", + "pos": [ + 110, + 378 + ], + "size": { + "0": 315, + "1": 126 + }, + "flags": {}, + "order": 9, + "mode": 2, + "inputs": [ + { + "name": "model", + "type": "MODEL", + "link": 45 + }, + { + "name": "clip", + "type": "CLIP", + "link": 46 + } + ], + "outputs": [ + { + "name": "MODEL", + "type": "MODEL", + "links": [ + 41 + ], + "shape": 3, + "slot_index": 0 + }, + { + "name": "CLIP", + "type": "CLIP", + "links": [ + 43, + 44 + ], + "shape": 3, + "slot_index": 1 + } + ], + "properties": { + "Node name for S&R": "LoraLoader" + }, + "widgets_values": [ + "宫崎骏漫画场景_宫崎骏画风场景1.0.safetensors", + 1, + 1 + ] + }, + { + "id": 49, + "type": "CheckpointLoaderSimple", + "pos": [ + -250, + 197 + ], + "size": { + "0": 315, + "1": 98 + }, + "flags": {}, + "order": 6, + "mode": 2, + "outputs": [ + { + "name": "MODEL", + "type": "MODEL", + "links": [ + 45 + ], + "shape": 3, + "slot_index": 0 + }, + { + "name": "CLIP", + "type": "CLIP", + "links": [ + 46 + ], + "shape": 3, + "slot_index": 1 + }, + { + "name": "VAE", + "type": "VAE", + "links": null, + "shape": 3 + } + ], + "properties": { + "Node name for S&R": "CheckpointLoaderSimple" + }, + "widgets_values": [ + "v1-5-pruned-emaonly.safetensors" + ] + }, + { + "id": 7, + "type": "CLIPTextEncode", + "pos": [ + 420, + 549 + ], + "size": { + "0": 425.27801513671875, + "1": 180.6060791015625 + }, + "flags": {}, + "order": 13, + "mode": 2, + "inputs": [ + { + "name": "clip", + "type": "CLIP", + "link": 44 + } + ], + "outputs": [ + { + "name": "CONDITIONING", + "type": "CONDITIONING", + "links": [ + 6 + ], + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "CLIPTextEncode" + }, + "widgets_values": [ + "ng_deepnegative_v1_75t,(badhandv4:1.2),EasyNegative,(worst quality:2)," + ] + }, + { + "id": 56, + "type": "LoadImage", + "pos": [ + 844, + 1476 + ], + "size": { + "0": 315, + "1": 314 + }, + "flags": {}, + "order": 7, + "mode": 2, + "outputs": [ + { + "name": "IMAGE", + "type": "IMAGE", + "links": [ + 59 + ], + "shape": 3, + "slot_index": 0 + }, + { + "name": "MASK", + "type": "MASK", + "links": null, + "shape": 3 + } + ], + "properties": { + "Node name for S&R": "LoadImage" + }, + "widgets_values": [ + "微信图片_20240714174743.png", + "image" + ] + }, + { + "id": 14, + "type": "Text2Prompt", + "pos": [ + -185, + -773 + ], + "size": { + "0": 400, + "1": 246 + }, + "flags": {}, + "order": 8, + "mode": 0, + "inputs": [ + { + "name": "model", + "type": "TEXT2PROMPT_MODEL", + "link": 11 + } + ], + "outputs": [ + { + "name": "STRING", + "type": "STRING", + "links": [ + 16 + ], + "shape": 3, + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "Text2Prompt" + }, + "widgets_values": [ + "Exquisite,many details,night scene,dream,moon,meteor,far away", + 128, + 0.2, + "disable", + "NO", + "must be in english and describe a picture according to follow the description below within 77 words: ", + "You are a helpful assistant." + ] + }, + { + "id": 18, + "type": "ShowText|fofo", + "pos": [ + 270, + -695 + ], + "size": { + "0": 315, + "1": 76 + }, + "flags": {}, + "order": 11, + "mode": 0, + "inputs": [ + { + "name": "text", + "type": "STRING", + "link": 16, + "widget": { + "name": "text" + } + } + ], + "outputs": [ + { + "name": "STRING", + "type": "STRING", + "links": [], + "shape": 6, + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "ShowText|fofo" + }, + "widgets_values": [ + "", + "A beautiful sunset over a vast expanse of sky, with many intricate details such as stars, craters, and clouds. The moon is far away, casting a soft glow across the landscape. The sky is a deep shade of purple, with black clouds forming on either side. The image captures the beauty and wonder of nature at its most stunning moment." + ] + } + ], + "links": [ + [ + 2, + 5, + 0, + 3, + 3, + "LATENT" + ], + [ + 6, + 7, + 0, + 3, + 2, + "CONDITIONING" + ], + [ + 7, + 3, + 0, + 8, + 0, + "LATENT" + ], + [ + 11, + 13, + 0, + 14, + 0, + "TEXT2PROMPT_MODEL" + ], + [ + 16, + 14, + 0, + 18, + 0, + "STRING" + ], + [ + 24, + 8, + 0, + 34, + 0, + "IMAGE" + ], + [ + 33, + 8, + 0, + 42, + 1, + "IMAGE" + ], + [ + 34, + 44, + 0, + 42, + 0, + "UPSCALE_MODEL" + ], + [ + 35, + 42, + 0, + 45, + 0, + "IMAGE" + ], + [ + 36, + 42, + 0, + 9, + 0, + "IMAGE" + ], + [ + 38, + 46, + 0, + 3, + 1, + "CONDITIONING" + ], + [ + 40, + 47, + 0, + 8, + 1, + "VAE" + ], + [ + 41, + 48, + 0, + 3, + 0, + "MODEL" + ], + [ + 43, + 48, + 1, + 46, + 0, + "CLIP" + ], + [ + 44, + 48, + 1, + 7, + 0, + "CLIP" + ], + [ + 45, + 49, + 0, + 48, + 0, + "MODEL" + ], + [ + 46, + 49, + 1, + 48, + 1, + "CLIP" + ], + [ + 48, + 50, + 0, + 46, + 1, + "STRING" + ], + [ + 49, + 53, + 0, + 52, + 0, + "IMAGE" + ], + [ + 50, + 54, + 0, + 53, + 0, + "UPSCALE_MODEL" + ], + [ + 52, + 53, + 0, + 55, + 0, + "IMAGE" + ], + [ + 59, + 56, + 0, + 53, + 1, + "IMAGE" + ] + ], + "groups": [ + { + "title": "Group", + "bounding": [ + -575, + -936, + 1197, + 458 + ], + "color": "#3f789e", + "font_size": 24 + }, + { + "title": "Group", + "bounding": [ + -278, + -451, + 2175, + 1363 + ], + "color": "#3f789e", + "font_size": 24 + }, + { + "title": "Group", + "bounding": [ + 784, + 1065, + 1105, + 717 + ], + "color": "#3f789e", + "font_size": 24 + } + ], + "config": {}, + "extra": { + "ds": { + "scale": 1.3310000000000006, + "offset": { + "0": -614.260986328125, + "1": -1347.4464111328125 + } + } + }, + "version": 0.4 +} \ No newline at end of file diff --git a/gen_sr.json b/gen_sr.json new file mode 100644 index 0000000..17bec71 --- /dev/null +++ b/gen_sr.json @@ -0,0 +1,132 @@ +{ + "3": { + "inputs": { + "seed": 104652449465535, + "steps": 20, + "cfg": 8, + "sampler_name": "euler", + "scheduler": "normal", + "denoise": 1, + "model": [ + "4", + 0 + ], + "positive": [ + "6", + 0 + ], + "negative": [ + "7", + 0 + ], + "latent_image": [ + "5", + 0 + ] + }, + "class_type": "KSampler", + "_meta": { + "title": "KSampler" + } + }, + "4": { + "inputs": { + "ckpt_name": "v1-5-pruned-emaonly.ckpt" + }, + "class_type": "CheckpointLoaderSimple", + "_meta": { + "title": "Load Checkpoint" + } + }, + "5": { + "inputs": { + "width": 512, + "height": 512, + "batch_size": 1 + }, + "class_type": "EmptyLatentImage", + "_meta": { + "title": "Empty Latent Image" + } + }, + "6": { + "inputs": { + "text": "masterpiece best quality girl standing in victorian clothing", + "clip": [ + "4", + 1 + ] + }, + "class_type": "CLIPTextEncode", + "_meta": { + "title": "CLIP Text Encode (Prompt)" + } + }, + "7": { + "inputs": { + "text": "bad hands", + "clip": [ + "4", + 1 + ] + }, + "class_type": "CLIPTextEncode", + "_meta": { + "title": "CLIP Text Encode (Prompt)" + } + }, + "8": { + "inputs": { + "samples": [ + "3", + 0 + ], + "vae": [ + "4", + 2 + ] + }, + "class_type": "VAEDecode", + "_meta": { + "title": "VAE Decode" + } + }, + "9": { + "inputs": { + "filename_prefix": "ComfyUI", + "images": [ + "14", + 0 + ] + }, + "class_type": "SaveImage", + "_meta": { + "title": "Save Image" + } + }, + "13": { + "inputs": { + "model_name": "RealESRGAN_x2.pth" + }, + "class_type": "UpscaleModelLoader", + "_meta": { + "title": "Load Upscale Model" + } + }, + "14": { + "inputs": { + "upscale_model": [ + "13", + 0 + ], + "image": [ + "8", + 0 + ] + }, + "class_type": "ImageUpscaleWithModel", + "_meta": { + "title": "Upscale Image (using Model)" + } + } +} \ No newline at end of file diff --git a/gen_sr.py b/gen_sr.py new file mode 100644 index 0000000..a7a24a0 --- /dev/null +++ b/gen_sr.py @@ -0,0 +1,184 @@ +import os +import random +import sys +from typing import Sequence, Mapping, Any, Union +import torch + + +def get_value_at_index(obj: Union[Sequence, Mapping], index: int) -> Any: + """Returns the value at the given index of a sequence or mapping. + + If the object is a sequence (like list or string), returns the value at the given index. + If the object is a mapping (like a dictionary), returns the value at the index-th key. + + Some return a dictionary, in these cases, we look for the "results" key + + Args: + obj (Union[Sequence, Mapping]): The object to retrieve the value from. + index (int): The index of the value to retrieve. + + Returns: + Any: The value at the given index. + + Raises: + IndexError: If the index is out of bounds for the object and the object is not a mapping. + """ + try: + return obj[index] + except KeyError: + return obj["result"][index] + + +def find_path(name: str, path: str = None) -> str: + """ + Recursively looks at parent folders starting from the given path until it finds the given name. + Returns the path as a Path object if found, or None otherwise. + """ + # If no path is given, use the current working directory + if path is None: + path = os.getcwd() + + # Check if the current directory contains the name + if name in os.listdir(path): + path_name = os.path.join(path, name) + print(f"{name} found: {path_name}") + return path_name + + # Get the parent directory + parent_directory = os.path.dirname(path) + + # If the parent directory is the same as the current directory, we've reached the root and stop the search + if parent_directory == path: + return None + + # Recursively call the function with the parent directory + return find_path(name, parent_directory) + + +def add_comfyui_directory_to_sys_path() -> None: + """ + Add 'ComfyUI' to the sys.path + """ + comfyui_path = find_path("ComfyUI") + if comfyui_path is not None and os.path.isdir(comfyui_path): + sys.path.append(comfyui_path) + print(f"'{comfyui_path}' added to sys.path") + + +def add_extra_model_paths() -> None: + """ + Parse the optional extra_model_paths.yaml file and add the parsed paths to the sys.path. + """ + from main import load_extra_path_config + + extra_model_paths = find_path("extra_model_paths.yaml") + + if extra_model_paths is not None: + load_extra_path_config(extra_model_paths) + else: + print("Could not find the extra_model_paths config file.") + + +add_comfyui_directory_to_sys_path() +add_extra_model_paths() + + +def import_custom_nodes() -> None: + """Find all custom nodes in the custom_nodes folder and add those node objects to NODE_CLASS_MAPPINGS + + This function sets up a new asyncio event loop, initializes the PromptServer, + creates a PromptQueue, and initializes the custom nodes. + """ + import asyncio + import execution + from nodes import init_extra_nodes + import server + + # # Creating a new event loop and setting it as the default loop + # loop = asyncio.new_event_loop() + # asyncio.set_event_loop(loop) + + # # Creating an instance of PromptServer with the loop + # server_instance = server.PromptServer(loop) + # execution.PromptQueue(server_instance) + + # Initializing custom nodes + init_extra_nodes(True) + + +from nodes import ( + SaveImage, + KSampler, + CLIPTextEncode, + EmptyLatentImage, + CheckpointLoaderSimple, + NODE_CLASS_MAPPINGS, + VAEDecode, +) + + +def main(): + import_custom_nodes() + with torch.inference_mode(): + checkpointloadersimple = CheckpointLoaderSimple() + checkpointloadersimple_4 = checkpointloadersimple.load_checkpoint( + ckpt_name="v1-5-pruned-emaonly.ckpt" + ) + + emptylatentimage = EmptyLatentImage() + emptylatentimage_5 = emptylatentimage.generate( + width=512, height=512, batch_size=1 + ) + + cliptextencode = CLIPTextEncode() + cliptextencode_6 = cliptextencode.encode( + text="masterpiece best quality girl standing in victorian clothing", + clip=get_value_at_index(checkpointloadersimple_4, 1), + ) + + cliptextencode_7 = cliptextencode.encode( + text="bad hands", clip=get_value_at_index(checkpointloadersimple_4, 1) + ) + + upscalemodelloader = NODE_CLASS_MAPPINGS["UpscaleModelLoader"]() + upscalemodelloader_13 = upscalemodelloader.load_model( + model_name="RealESRGAN_x2.pth" + ) + + ksampler = KSampler() + vaedecode = VAEDecode() + imageupscalewithmodel = NODE_CLASS_MAPPINGS["ImageUpscaleWithModel"]() + saveimage = SaveImage() + + for q in range(1): + ksampler_3 = ksampler.sample( + seed=random.randint(1, 2**64), + steps=20, + cfg=8, + sampler_name="euler", + scheduler="normal", + denoise=1, + model=get_value_at_index(checkpointloadersimple_4, 0), + positive=get_value_at_index(cliptextencode_6, 0), + negative=get_value_at_index(cliptextencode_7, 0), + latent_image=get_value_at_index(emptylatentimage_5, 0), + ) + + vaedecode_8 = vaedecode.decode( + samples=get_value_at_index(ksampler_3, 0), + vae=get_value_at_index(checkpointloadersimple_4, 2), + ) + + imageupscalewithmodel_14 = imageupscalewithmodel.upscale( + upscale_model=get_value_at_index(upscalemodelloader_13, 0), + image=get_value_at_index(vaedecode_8, 0), + ) + + saveimage_9 = saveimage.save_images( + filename_prefix="ComfyUI", + images=get_value_at_index(imageupscalewithmodel_14, 0), + ) + + +if __name__ == "__main__": + main() diff --git a/image_matting.json b/image_matting.json new file mode 100644 index 0000000..3aeecd7 --- /dev/null +++ b/image_matting.json @@ -0,0 +1,567 @@ +{ + "last_node_id": 12, + "last_link_id": 13, + "nodes": [ + { + "id": 1, + "type": "SAMModelLoader (segment anything)", + "pos": [ + 666.7272338867188, + 1041.272705078125 + ], + "size": { + "0": 315, + "1": 58 + }, + "flags": {}, + "order": 0, + "mode": 0, + "outputs": [ + { + "name": "SAM_MODEL", + "type": "SAM_MODEL", + "links": [ + 1 + ], + "shape": 3, + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "SAMModelLoader (segment anything)" + }, + "widgets_values": [ + "sam_hq_vit_h (2.57GB)" + ] + }, + { + "id": 2, + "type": "GroundingDinoModelLoader (segment anything)", + "pos": [ + 662.7272338867188, + 935.272705078125 + ], + "size": { + "0": 361.20001220703125, + "1": 58 + }, + "flags": {}, + "order": 1, + "mode": 0, + "outputs": [ + { + "name": "GROUNDING_DINO_MODEL", + "type": "GROUNDING_DINO_MODEL", + "links": [ + 2 + ], + "shape": 3, + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "GroundingDinoModelLoader (segment anything)" + }, + "widgets_values": [ + "GroundingDINO_SwinT_OGC (694MB)" + ] + }, + { + "id": 12, + "type": "LoadImage", + "pos": [ + 677, + 569 + ], + "size": { + "0": 315, + "1": 314 + }, + "flags": {}, + "order": 2, + "mode": 0, + "outputs": [ + { + "name": "IMAGE", + "type": "IMAGE", + "links": [ + 3, + 10 + ], + "shape": 3, + "slot_index": 0 + }, + { + "name": "MASK", + "type": "MASK", + "links": null, + "shape": 3 + } + ], + "properties": { + "Node name for S&R": "LoadImage" + }, + "widgets_values": [ + "test.png", + "image" + ] + }, + { + "id": 8, + "type": "MattingModelLoader", + "pos": [ + 679, + 444 + ], + "size": { + "0": 315, + "1": 78 + }, + "flags": {}, + "order": 3, + "mode": 0, + "outputs": [ + { + "name": "MATTING_MODEL", + "type": "MATTING_MODEL", + "links": [ + 8 + ], + "shape": 3, + "slot_index": 0 + }, + { + "name": "MATTING_PREPROCESSOR", + "type": "MATTING_PREPROCESSOR", + "links": [ + 9 + ], + "shape": 3, + "slot_index": 1 + } + ], + "properties": { + "Node name for S&R": "MattingModelLoader" + }, + "widgets_values": [ + "vitmatte_small (103 MB)" + ] + }, + { + "id": 9, + "type": "ApplyMatting", + "pos": [ + 1084, + 474 + ], + "size": { + "0": 330, + "1": 86 + }, + "flags": {}, + "order": 7, + "mode": 0, + "inputs": [ + { + "name": "matting_model", + "type": "MATTING_MODEL", + "link": 8 + }, + { + "name": "matting_preprocessor", + "type": "MATTING_PREPROCESSOR", + "link": 9 + }, + { + "name": "image", + "type": "IMAGE", + "link": 10 + }, + { + "name": "trimap", + "type": "MASK", + "link": 11 + } + ], + "outputs": [ + { + "name": "IMAGE", + "type": "IMAGE", + "links": [ + 7 + ], + "shape": 3, + "slot_index": 0 + }, + { + "name": "MASK", + "type": "MASK", + "links": [ + 12 + ], + "shape": 3, + "slot_index": 1 + } + ], + "properties": { + "Node name for S&R": "ApplyMatting" + } + }, + { + "id": 3, + "type": "GroundingDinoSAMSegment (segment anything)", + "pos": [ + 1081, + 615 + ], + "size": { + "0": 352.79998779296875, + "1": 122 + }, + "flags": {}, + "order": 4, + "mode": 0, + "inputs": [ + { + "name": "sam_model", + "type": "SAM_MODEL", + "link": 1 + }, + { + "name": "grounding_dino_model", + "type": "GROUNDING_DINO_MODEL", + "link": 2 + }, + { + "name": "image", + "type": "IMAGE", + "link": 3 + } + ], + "outputs": [ + { + "name": "IMAGE", + "type": "IMAGE", + "links": [], + "shape": 3, + "slot_index": 0 + }, + { + "name": "MASK", + "type": "MASK", + "links": [ + 13 + ], + "shape": 3, + "slot_index": 1 + } + ], + "properties": { + "Node name for S&R": "GroundingDinoSAMSegment (segment anything)" + }, + "widgets_values": [ + "necklace", + 0.3 + ] + }, + { + "id": 11, + "type": "CreateTrimap", + "pos": [ + 1491, + 606 + ], + "size": { + "0": 315, + "1": 130 + }, + "flags": {}, + "order": 5, + "mode": 0, + "inputs": [ + { + "name": "mask", + "type": "MASK", + "link": 13 + } + ], + "outputs": [ + { + "name": "MASK", + "type": "MASK", + "links": [ + 5, + 11 + ], + "shape": 3, + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "CreateTrimap" + }, + "widgets_values": [ + 25 + ] + }, + { + "id": 7, + "type": "PreviewImage", + "pos": [ + 1501, + 312 + ], + "size": { + "0": 210, + "1": 246 + }, + "flags": {}, + "order": 9, + "mode": 0, + "inputs": [ + { + "name": "images", + "type": "IMAGE", + "link": 7 + } + ], + "properties": { + "Node name for S&R": "PreviewImage" + } + }, + { + "id": 10, + "type": "MaskToImage", + "pos": [ + 1510, + 782 + ], + "size": { + "0": 210, + "1": 26 + }, + "flags": {}, + "order": 10, + "mode": 0, + "inputs": [ + { + "name": "mask", + "type": "MASK", + "link": 12 + } + ], + "outputs": [ + { + "name": "IMAGE", + "type": "IMAGE", + "links": [ + 6 + ], + "shape": 3, + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "MaskToImage" + } + }, + { + "id": 6, + "type": "PreviewImage", + "pos": [ + 1773, + 322 + ], + "size": { + "0": 210, + "1": 246 + }, + "flags": {}, + "order": 11, + "mode": 0, + "inputs": [ + { + "name": "images", + "type": "IMAGE", + "link": 6 + } + ], + "properties": { + "Node name for S&R": "PreviewImage" + } + }, + { + "id": 5, + "type": "MaskToImage", + "pos": [ + 1523, + 860 + ], + "size": { + "0": 210, + "1": 26 + }, + "flags": { + "collapsed": false + }, + "order": 6, + "mode": 0, + "inputs": [ + { + "name": "mask", + "type": "MASK", + "link": 5 + } + ], + "outputs": [ + { + "name": "IMAGE", + "type": "IMAGE", + "links": [ + 4 + ], + "shape": 3, + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "MaskToImage" + } + }, + { + "id": 4, + "type": "PreviewImage", + "pos": [ + 1846, + 665 + ], + "size": { + "0": 210, + "1": 246 + }, + "flags": {}, + "order": 8, + "mode": 0, + "inputs": [ + { + "name": "images", + "type": "IMAGE", + "link": 4 + } + ], + "properties": { + "Node name for S&R": "PreviewImage" + } + } + ], + "links": [ + [ + 1, + 1, + 0, + 3, + 0, + "SAM_MODEL" + ], + [ + 2, + 2, + 0, + 3, + 1, + "GROUNDING_DINO_MODEL" + ], + [ + 3, + 12, + 0, + 3, + 2, + "IMAGE" + ], + [ + 4, + 5, + 0, + 4, + 0, + "IMAGE" + ], + [ + 5, + 11, + 0, + 5, + 0, + "MASK" + ], + [ + 6, + 10, + 0, + 6, + 0, + "IMAGE" + ], + [ + 7, + 9, + 0, + 7, + 0, + "IMAGE" + ], + [ + 8, + 8, + 0, + 9, + 0, + "MATTING_MODEL" + ], + [ + 9, + 8, + 1, + 9, + 1, + "MATTING_PREPROCESSOR" + ], + [ + 10, + 12, + 0, + 9, + 2, + "IMAGE" + ], + [ + 11, + 11, + 0, + 9, + 3, + "MASK" + ], + [ + 12, + 9, + 1, + 10, + 0, + "MASK" + ], + [ + 13, + 3, + 1, + 11, + 0, + "MASK" + ] + ], + "groups": [], + "config": {}, + "extra": {}, + "version": 0.4 +} \ No newline at end of file diff --git a/image_text_matting.json b/image_text_matting.json new file mode 100644 index 0000000..68a3dae --- /dev/null +++ b/image_text_matting.json @@ -0,0 +1,158 @@ +{ + "1": { + "inputs": { + "model_name": "sam_hq_vit_h (2.57GB)" + }, + "class_type": "SAMModelLoader (segment anything)", + "_meta": { + "title": "SAMModelLoader (segment anything)" + } + }, + "2": { + "inputs": { + "model_name": "GroundingDINO_SwinT_OGC (694MB)" + }, + "class_type": "GroundingDinoModelLoader (segment anything)", + "_meta": { + "title": "GroundingDinoModelLoader (segment anything)" + } + }, + "3": { + "inputs": { + "prompt": "girl", + "threshold": 0.3, + "sam_model": [ + "1", + 0 + ], + "grounding_dino_model": [ + "2", + 0 + ], + "image": [ + "12", + 0 + ] + }, + "class_type": "GroundingDinoSAMSegment (segment anything)", + "_meta": { + "title": "GroundingDinoSAMSegment (segment anything)" + } + }, + "4": { + "inputs": { + "images": [ + "5", + 0 + ] + }, + "class_type": "PreviewImage", + "_meta": { + "title": "Preview Image" + } + }, + "5": { + "inputs": { + "mask": [ + "11", + 0 + ] + }, + "class_type": "MaskToImage", + "_meta": { + "title": "Convert Mask to Image" + } + }, + "6": { + "inputs": { + "images": [ + "10", + 0 + ] + }, + "class_type": "PreviewImage", + "_meta": { + "title": "Preview Image" + } + }, + "7": { + "inputs": { + "images": [ + "9", + 0 + ] + }, + "class_type": "PreviewImage", + "_meta": { + "title": "Preview Image" + } + }, + "8": { + "inputs": { + "model_name": "vitmatte_small (103 MB)" + }, + "class_type": "MattingModelLoader", + "_meta": { + "title": "Load Matting Model" + } + }, + "9": { + "inputs": { + "matting_model": [ + "8", + 0 + ], + "matting_preprocessor": [ + "8", + 1 + ], + "image": [ + "12", + 0 + ], + "trimap": [ + "11", + 0 + ] + }, + "class_type": "ApplyMatting", + "_meta": { + "title": "Apply Matting" + } + }, + "10": { + "inputs": { + "mask": [ + "9", + 1 + ] + }, + "class_type": "MaskToImage", + "_meta": { + "title": "Convert Mask to Image" + } + }, + "11": { + "inputs": { + "kernel_size": 20.86, + "mask": [ + "3", + 1 + ] + }, + "class_type": "CreateTrimap", + "_meta": { + "title": "Create Trimap" + } + }, + "12": { + "inputs": { + "image": "IMG_1956.JPG", + "upload": "image" + }, + "class_type": "LoadImage", + "_meta": { + "title": "Load Image" + } + } +} \ No newline at end of file diff --git a/image_text_to_image.json b/image_text_to_image.json new file mode 100644 index 0000000..7515965 --- /dev/null +++ b/image_text_to_image.json @@ -0,0 +1,122 @@ +{ + "3": { + "inputs": { + "seed": 826827124911811, + "steps": 20, + "cfg": 8, + "sampler_name": "dpmpp_2m", + "scheduler": "normal", + "denoise": 0.8700000000000001, + "model": [ + "14", + 0 + ], + "positive": [ + "6", + 0 + ], + "negative": [ + "7", + 0 + ], + "latent_image": [ + "12", + 0 + ] + }, + "class_type": "KSampler", + "_meta": { + "title": "KSampler" + } + }, + "6": { + "inputs": { + "text": "photograph of victorian woman with wings, sky clouds, meadow grass\n", + "clip": [ + "14", + 1 + ] + }, + "class_type": "CLIPTextEncode", + "_meta": { + "title": "CLIP Text Encode (Prompt)" + } + }, + "7": { + "inputs": { + "text": "watermark, text\n", + "clip": [ + "14", + 1 + ] + }, + "class_type": "CLIPTextEncode", + "_meta": { + "title": "CLIP Text Encode (Prompt)" + } + }, + "8": { + "inputs": { + "samples": [ + "3", + 0 + ], + "vae": [ + "14", + 2 + ] + }, + "class_type": "VAEDecode", + "_meta": { + "title": "VAE Decode" + } + }, + "9": { + "inputs": { + "filename_prefix": "ComfyUI", + "images": [ + "8", + 0 + ] + }, + "class_type": "SaveImage", + "_meta": { + "title": "Save Image" + } + }, + "10": { + "inputs": { + "image": "example.png", + "upload": "image" + }, + "class_type": "LoadImage", + "_meta": { + "title": "Load Image" + } + }, + "12": { + "inputs": { + "pixels": [ + "10", + 0 + ], + "vae": [ + "14", + 2 + ] + }, + "class_type": "VAEEncode", + "_meta": { + "title": "VAE Encode" + } + }, + "14": { + "inputs": { + "ckpt_name": "v1-5-pruned-emaonly.ckpt" + }, + "class_type": "CheckpointLoaderSimple", + "_meta": { + "title": "Load Checkpoint" + } + } +} \ No newline at end of file diff --git a/utils.py b/utils.py index e55f26e..5bf6c8a 100644 --- a/utils.py +++ b/utils.py @@ -13,7 +13,7 @@ def import_custom_nodes() -> None: """ import asyncio import execution - from nodes import init_custom_nodes + from nodes import init_extra_nodes import server # Creating a new event loop and setting it as the default loop @@ -25,7 +25,7 @@ def import_custom_nodes() -> None: execution.PromptQueue(server_instance) # Initializing custom nodes - init_custom_nodes() + init_extra_nodes(True) def find_path(name: str, path: str = None) -> str: @@ -68,7 +68,7 @@ def add_extra_model_paths() -> None: """ Parse the optional extra_model_paths.yaml file and add the parsed paths to the sys.path. """ - from main import load_extra_path_config + from main_utils import load_extra_path_config extra_model_paths = find_path("extra_model_paths.yaml") diff --git a/workflow_api.json b/workflow_api.json new file mode 100644 index 0000000..fff8a13 --- /dev/null +++ b/workflow_api.json @@ -0,0 +1,107 @@ +{ + "3": { + "inputs": { + "seed": 238072909150278, + "steps": 20, + "cfg": 8, + "sampler_name": "euler", + "scheduler": "normal", + "denoise": 1, + "model": [ + "4", + 0 + ], + "positive": [ + "6", + 0 + ], + "negative": [ + "7", + 0 + ], + "latent_image": [ + "5", + 0 + ] + }, + "class_type": "KSampler", + "_meta": { + "title": "KSampler" + } + }, + "4": { + "inputs": { + "ckpt_name": "v1-5-pruned-emaonly.ckpt" + }, + "class_type": "CheckpointLoaderSimple", + "_meta": { + "title": "Load Checkpoint" + } + }, + "5": { + "inputs": { + "width": 512, + "height": 512, + "batch_size": 1 + }, + "class_type": "EmptyLatentImage", + "_meta": { + "title": "Empty Latent Image" + } + }, + "6": { + "inputs": { + "text": "beautiful scenery nature glass bottle landscape, , purple galaxy bottle,", + "clip": [ + "4", + 1 + ] + }, + "class_type": "CLIPTextEncode", + "_meta": { + "title": "CLIP Text Encode (Prompt)" + } + }, + "7": { + "inputs": { + "text": "text, watermark", + "clip": [ + "4", + 1 + ] + }, + "class_type": "CLIPTextEncode", + "_meta": { + "title": "CLIP Text Encode (Prompt)" + } + }, + "8": { + "inputs": { + "samples": [ + "3", + 0 + ], + "vae": [ + "4", + 2 + ] + }, + "class_type": "VAEDecode", + "_meta": { + "title": "VAE Decode" + } + }, + "9": { + "inputs": { + "filename_prefix": "ComfyUI", + "images": [ + "8", + 0 + ] + }, + "class_type": "SaveImage", + "_meta": { + "title": "Save Image" + } + } +} \ No newline at end of file diff --git a/workflow_api.py b/workflow_api.py new file mode 100644 index 0000000..f1a3ed7 --- /dev/null +++ b/workflow_api.py @@ -0,0 +1,147 @@ +import os +import random +import sys +from typing import Sequence, Mapping, Any, Union +import torch + + +def get_value_at_index(obj: Union[Sequence, Mapping], index: int) -> Any: + """Returns the value at the given index of a sequence or mapping. + + If the object is a sequence (like list or string), returns the value at the given index. + If the object is a mapping (like a dictionary), returns the value at the index-th key. + + Some return a dictionary, in these cases, we look for the "results" key + + Args: + obj (Union[Sequence, Mapping]): The object to retrieve the value from. + index (int): The index of the value to retrieve. + + Returns: + Any: The value at the given index. + + Raises: + IndexError: If the index is out of bounds for the object and the object is not a mapping. + """ + try: + return obj[index] + except KeyError: + return obj["result"][index] + + +def find_path(name: str, path: str = None) -> str: + """ + Recursively looks at parent folders starting from the given path until it finds the given name. + Returns the path as a Path object if found, or None otherwise. + """ + # If no path is given, use the current working directory + if path is None: + path = os.getcwd() + + # Check if the current directory contains the name + if name in os.listdir(path): + path_name = os.path.join(path, name) + print(f"{name} found: {path_name}") + return path_name + + # Get the parent directory + parent_directory = os.path.dirname(path) + + # If the parent directory is the same as the current directory, we've reached the root and stop the search + if parent_directory == path: + return None + + # Recursively call the function with the parent directory + return find_path(name, parent_directory) + + +def add_comfyui_directory_to_sys_path() -> None: + """ + Add 'ComfyUI' to the sys.path + """ + comfyui_path = find_path("ComfyUI") + if comfyui_path is not None and os.path.isdir(comfyui_path): + sys.path.append(comfyui_path) + print(f"'{comfyui_path}' added to sys.path") + + +def add_extra_model_paths() -> None: + """ + Parse the optional extra_model_paths.yaml file and add the parsed paths to the sys.path. + """ + from main import load_extra_path_config + + extra_model_paths = find_path("extra_model_paths.yaml") + + if extra_model_paths is not None: + load_extra_path_config(extra_model_paths) + else: + print("Could not find the extra_model_paths config file.") + + +add_comfyui_directory_to_sys_path() +add_extra_model_paths() + +from nodes import ( + CLIPTextEncode, + EmptyLatentImage, + VAEDecode, + KSampler, + NODE_CLASS_MAPPINGS, + CheckpointLoaderSimple, + SaveImage, +) + + +def main(): + with torch.inference_mode(): + checkpointloadersimple = CheckpointLoaderSimple() + checkpointloadersimple_4 = checkpointloadersimple.load_checkpoint( + ckpt_name="v1-5-pruned-emaonly.ckpt" + ) + + emptylatentimage = EmptyLatentImage() + emptylatentimage_5 = emptylatentimage.generate( + width=512, height=512, batch_size=1 + ) + + cliptextencode = CLIPTextEncode() + cliptextencode_6 = cliptextencode.encode( + text="beautiful scenery nature glass bottle landscape, , purple galaxy bottle,", + clip=get_value_at_index(checkpointloadersimple_4, 1), + ) + + cliptextencode_7 = cliptextencode.encode( + text="text, watermark", clip=get_value_at_index(checkpointloadersimple_4, 1) + ) + + ksampler = KSampler() + vaedecode = VAEDecode() + saveimage = SaveImage() + + for q in range(1): + ksampler_3 = ksampler.sample( + seed=random.randint(1, 2**64), + steps=20, + cfg=8, + sampler_name="euler", + scheduler="normal", + denoise=1, + model=get_value_at_index(checkpointloadersimple_4, 0), + positive=get_value_at_index(cliptextencode_6, 0), + negative=get_value_at_index(cliptextencode_7, 0), + latent_image=get_value_at_index(emptylatentimage_5, 0), + ) + + vaedecode_8 = vaedecode.decode( + samples=get_value_at_index(ksampler_3, 0), + vae=get_value_at_index(checkpointloadersimple_4, 2), + ) + + saveimage_9 = saveimage.save_images( + filename_prefix="ComfyUI", images=get_value_at_index(vaedecode_8, 0) + ) + + +if __name__ == "__main__": + main()