mirror of
https://github.com/jags111/efficiency-nodes-comfyui.git
synced 2026-03-21 21:22:13 -03:00
@@ -1,7 +1,10 @@
|
|||||||
# Efficiency Nodes - A collection of my ComfyUI custom nodes to help streamline workflows and reduce total node count.
|
# Efficiency Nodes - A collection of my ComfyUI custom nodes to help streamline workflows and reduce total node count.
|
||||||
# by Luciano Cirino (Discord: TSC#9184) - April 2023
|
# by Luciano Cirino (Discord: TSC#9184) - April 2023
|
||||||
|
|
||||||
from PIL import Image, ImageFilter, ImageEnhance, ImageOps, ImageDraw, ImageChops, ImageFont
|
from comfy.sd import ModelPatcher, CLIP, VAE
|
||||||
|
from nodes import common_ksampler
|
||||||
|
from torch import Tensor
|
||||||
|
from PIL import Image, ImageOps
|
||||||
from PIL.PngImagePlugin import PngInfo
|
from PIL.PngImagePlugin import PngInfo
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import torch
|
import torch
|
||||||
@@ -9,16 +12,8 @@ import torch
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import json
|
import json
|
||||||
import hashlib
|
|
||||||
import copy
|
|
||||||
import traceback
|
|
||||||
import copy
|
|
||||||
import folder_paths
|
import folder_paths
|
||||||
|
|
||||||
import model_management
|
|
||||||
import importlib
|
|
||||||
import random
|
|
||||||
|
|
||||||
# Get the absolute path of the parent directory of the current script
|
# Get the absolute path of the parent directory of the current script
|
||||||
my_dir = os.path.dirname(os.path.abspath(__file__))
|
my_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
||||||
@@ -29,7 +24,6 @@ comfy_dir = os.path.abspath(os.path.join(my_dir, '..', '..'))
|
|||||||
sys.path.append(comfy_dir)
|
sys.path.append(comfy_dir)
|
||||||
|
|
||||||
# Import functions from nodes.py in the ComfyUI directory
|
# Import functions from nodes.py in the ComfyUI directory
|
||||||
from nodes import common_ksampler, before_node_execution, interrupt_processing
|
|
||||||
import comfy.samplers
|
import comfy.samplers
|
||||||
import comfy.sd
|
import comfy.sd
|
||||||
import comfy.utils
|
import comfy.utils
|
||||||
@@ -56,7 +50,7 @@ loaded_objects = {
|
|||||||
class TSC_EfficientLoader:
|
class TSC_EfficientLoader:
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def INPUT_TYPES(s):
|
def INPUT_TYPES(cls):
|
||||||
return {"required": { "ckpt_name": (folder_paths.get_filename_list("checkpoints"), ),
|
return {"required": { "ckpt_name": (folder_paths.get_filename_list("checkpoints"), ),
|
||||||
"vae_name": (["Baked VAE"] + folder_paths.get_filename_list("vae"),),
|
"vae_name": (["Baked VAE"] + folder_paths.get_filename_list("vae"),),
|
||||||
"clip_skip": ("INT", {"default": -1, "min": -24, "max": -1, "step": 1}),
|
"clip_skip": ("INT", {"default": -1, "min": -24, "max": -1, "step": 1}),
|
||||||
@@ -80,6 +74,10 @@ class TSC_EfficientLoader:
|
|||||||
if vae_name == "Baked VAE":
|
if vae_name == "Baked VAE":
|
||||||
output_vae = True
|
output_vae = True
|
||||||
|
|
||||||
|
model: ModelPatcher | None = None
|
||||||
|
clip: CLIP | None = None
|
||||||
|
vae: VAE | None = None
|
||||||
|
|
||||||
# Search for tuple index that contains ckpt_name in "ckpt" array of loaded_lbjects
|
# Search for tuple index that contains ckpt_name in "ckpt" array of loaded_lbjects
|
||||||
checkpoint_found = False
|
checkpoint_found = False
|
||||||
for i, entry in enumerate(loaded_objects["ckpt"]):
|
for i, entry in enumerate(loaded_objects["ckpt"]):
|
||||||
@@ -121,6 +119,8 @@ class TSC_EfficientLoader:
|
|||||||
loaded_objects["vae"].append((vae_name, vae))
|
loaded_objects["vae"].append((vae_name, vae))
|
||||||
|
|
||||||
# CLIP skip
|
# CLIP skip
|
||||||
|
if not clip:
|
||||||
|
raise Exception("No CLIP found")
|
||||||
clip = clip.clone()
|
clip = clip.clone()
|
||||||
clip.clip_layer(clip_skip)
|
clip.clip_layer(clip_skip)
|
||||||
|
|
||||||
@@ -128,7 +128,7 @@ class TSC_EfficientLoader:
|
|||||||
|
|
||||||
|
|
||||||
# TSC KSampler (Efficient)
|
# TSC KSampler (Efficient)
|
||||||
last_helds = {
|
last_helds: dict[str, list] = {
|
||||||
"results": [None for _ in range(15)],
|
"results": [None for _ in range(15)],
|
||||||
"latent": [None for _ in range(15)],
|
"latent": [None for _ in range(15)],
|
||||||
"images": [None for _ in range(15)]
|
"images": [None for _ in range(15)]
|
||||||
@@ -140,7 +140,7 @@ class TSC_KSampler:
|
|||||||
self.type = "temp"
|
self.type = "temp"
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def INPUT_TYPES(s):
|
def INPUT_TYPES(cls):
|
||||||
return {"required":
|
return {"required":
|
||||||
{"sampler_state": (["Sample", "Hold"], ),
|
{"sampler_state": (["Sample", "Hold"], ),
|
||||||
"my_unique_id": ("INT", {"default": 0, "min": 0, "max": 15}),
|
"my_unique_id": ("INT", {"default": 0, "min": 0, "max": 15}),
|
||||||
@@ -199,6 +199,8 @@ class TSC_KSampler:
|
|||||||
last_images = empty_image
|
last_images = empty_image
|
||||||
else:
|
else:
|
||||||
last_images = last_helds["images"][my_unique_id]
|
last_images = last_helds["images"][my_unique_id]
|
||||||
|
|
||||||
|
latent: Tensor|None = None
|
||||||
|
|
||||||
if sampler_state == "Sample":
|
if sampler_state == "Sample":
|
||||||
samples = common_ksampler(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, denoise=denoise)
|
samples = common_ksampler(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, denoise=denoise)
|
||||||
@@ -364,7 +366,7 @@ class TSC_ImageOverlay:
|
|||||||
# TSC Evaluate Integers
|
# TSC Evaluate Integers
|
||||||
class TSC_EvaluateInts:
|
class TSC_EvaluateInts:
|
||||||
@classmethod
|
@classmethod
|
||||||
def INPUT_TYPES(s):
|
def INPUT_TYPES(cls):
|
||||||
return {"required": {
|
return {"required": {
|
||||||
"python_expression": ("STRING", {"default": "((a + b) - c) / 2", "multiline": False}),
|
"python_expression": ("STRING", {"default": "((a + b) - c) / 2", "multiline": False}),
|
||||||
"print_to_console": (["False", "True"],),},
|
"print_to_console": (["False", "True"],),},
|
||||||
@@ -391,7 +393,7 @@ class TSC_EvaluateInts:
|
|||||||
# TSC Evaluate Strings
|
# TSC Evaluate Strings
|
||||||
class TSC_EvaluateStrs:
|
class TSC_EvaluateStrs:
|
||||||
@classmethod
|
@classmethod
|
||||||
def INPUT_TYPES(s):
|
def INPUT_TYPES(cls):
|
||||||
return {"required": {
|
return {"required": {
|
||||||
"python_expression": ("STRING", {"default": "a + b + c", "multiline": False}),
|
"python_expression": ("STRING", {"default": "a + b + c", "multiline": False}),
|
||||||
"print_to_console": (["False", "True"],)},
|
"print_to_console": (["False", "True"],)},
|
||||||
|
|||||||
Reference in New Issue
Block a user