Skip to content
This repository has been archived by the owner on Jan 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1 from DrJKL/cleanup
Browse files Browse the repository at this point in the history
Small cleanups
  • Loading branch information
LucianoCirino authored Apr 10, 2023
2 parents 547df76 + ee66e4b commit f39f666
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions efficiency_nodes.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
# 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

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
import numpy as np
import torch

import os
import sys
import json
import hashlib
import copy
import traceback
import copy
import folder_paths

import model_management
import importlib
import random

# Get the absolute path of the parent directory of the current script
my_dir = os.path.dirname(os.path.abspath(__file__))

Expand All @@ -29,7 +24,6 @@
sys.path.append(comfy_dir)

# Import functions from nodes.py in the ComfyUI directory
from nodes import common_ksampler, before_node_execution, interrupt_processing
import comfy.samplers
import comfy.sd
import comfy.utils
Expand All @@ -56,7 +50,7 @@ def pil2tensor(image: Image.Image) -> torch.Tensor:
class TSC_EfficientLoader:

@classmethod
def INPUT_TYPES(s):
def INPUT_TYPES(cls):
return {"required": { "ckpt_name": (folder_paths.get_filename_list("checkpoints"), ),
"vae_name": (["Baked VAE"] + folder_paths.get_filename_list("vae"),),
"clip_skip": ("INT", {"default": -1, "min": -24, "max": -1, "step": 1}),
Expand All @@ -80,6 +74,10 @@ def efficientloader(self, ckpt_name, vae_name, clip_skip, positive, negative, em
if vae_name == "Baked VAE":
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
checkpoint_found = False
for i, entry in enumerate(loaded_objects["ckpt"]):
Expand Down Expand Up @@ -121,14 +119,16 @@ def efficientloader(self, ckpt_name, vae_name, clip_skip, positive, negative, em
loaded_objects["vae"].append((vae_name, vae))

# CLIP skip
if not clip:
raise Exception("No CLIP found")
clip = clip.clone()
clip.clip_layer(clip_skip)

return (model, [[clip.encode(positive), {}]], [[clip.encode(negative), {}]], {"samples":latent}, vae, clip, )


# TSC KSampler (Efficient)
last_helds = {
last_helds: dict[str, list] = {
"results": [None for _ in range(15)],
"latent": [None for _ in range(15)],
"images": [None for _ in range(15)]
Expand All @@ -140,7 +140,7 @@ def __init__(self):
self.type = "temp"

@classmethod
def INPUT_TYPES(s):
def INPUT_TYPES(cls):
return {"required":
{"sampler_state": (["Sample", "Hold"], ),
"my_unique_id": ("INT", {"default": 0, "min": 0, "max": 15}),
Expand Down Expand Up @@ -199,6 +199,8 @@ def sample(self, sampler_state, my_unique_id, model, seed, steps, cfg, sampler_n
last_images = empty_image
else:
last_images = last_helds["images"][my_unique_id]

latent: Tensor|None = None

if sampler_state == "Sample":
samples = common_ksampler(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, denoise=denoise)
Expand Down Expand Up @@ -364,7 +366,7 @@ def apply_overlay(self, base, overlay, size_option, resize_method, rescale_facto
# TSC Evaluate Integers
class TSC_EvaluateInts:
@classmethod
def INPUT_TYPES(s):
def INPUT_TYPES(cls):
return {"required": {
"python_expression": ("STRING", {"default": "((a + b) - c) / 2", "multiline": False}),
"print_to_console": (["False", "True"],),},
Expand All @@ -391,7 +393,7 @@ def evaluate(self, python_expression, print_to_console, a=0, b=0, c=0):
# TSC Evaluate Strings
class TSC_EvaluateStrs:
@classmethod
def INPUT_TYPES(s):
def INPUT_TYPES(cls):
return {"required": {
"python_expression": ("STRING", {"default": "a + b + c", "multiline": False}),
"print_to_console": (["False", "True"],)},
Expand Down

0 comments on commit f39f666

Please sign in to comment.