Skip to content

Commit

Permalink
Merge PR #131 from Kosinkadink/develop - node autosize + maintenance
Browse files Browse the repository at this point in the history
Node Autosize + Maintenance
  • Loading branch information
Kosinkadink committed Jul 16, 2024
2 parents 56000f3 + 10ad2e6 commit 95d00fc
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 10 deletions.
3 changes: 2 additions & 1 deletion __init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .adv_control.nodes import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS

__all__ = ['NODE_CLASS_MAPPINGS', 'NODE_DISPLAY_NAME_MAPPINGS']
WEB_DIRECTORY = "./web"
__all__ = ['NODE_CLASS_MAPPINGS', 'NODE_DISPLAY_NAME_MAPPINGS', "WEB_DIRECTORY"]
18 changes: 13 additions & 5 deletions adv_control/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def INPUT_TYPES(s):
"control_net_name": (folder_paths.get_filename_list("controlnet"), ),
},
"optional": {
"timestep_keyframe": ("TIMESTEP_KEYFRAME", ),
"tk_optional": ("TIMESTEP_KEYFRAME", ),
}
}

Expand All @@ -36,10 +36,13 @@ def INPUT_TYPES(s):
CATEGORY = "Adv-ControlNet 🛂🅐🅒🅝"

def load_controlnet(self, control_net_name,
timestep_keyframe: TimestepKeyframeGroup=None
tk_optional: TimestepKeyframeGroup=None,
timestep_keyframe: TimestepKeyframeGroup=None,
):
if timestep_keyframe is not None: # backwards compatibility
tk_optional = timestep_keyframe
controlnet_path = folder_paths.get_full_path("controlnet", control_net_name)
controlnet = load_controlnet(controlnet_path, timestep_keyframe)
controlnet = load_controlnet(controlnet_path, tk_optional)
return (controlnet,)


Expand All @@ -52,7 +55,8 @@ def INPUT_TYPES(s):
"control_net_name": (folder_paths.get_filename_list("controlnet"), )
},
"optional": {
"timestep_keyframe": ("TIMESTEP_KEYFRAME", ),
"tk_optional": ("TIMESTEP_KEYFRAME", ),
"autosize": ("ACNAUTOSIZE", {"padding": 160}),
}
}

Expand All @@ -62,10 +66,13 @@ def INPUT_TYPES(s):
CATEGORY = "Adv-ControlNet 🛂🅐🅒🅝"

def load_controlnet(self, control_net_name, model,
tk_optional: TimestepKeyframeGroup=None,
timestep_keyframe: TimestepKeyframeGroup=None
):
if timestep_keyframe is not None: # backwards compatibility
tk_optional = timestep_keyframe
controlnet_path = folder_paths.get_full_path("controlnet", control_net_name)
controlnet = load_controlnet(controlnet_path, timestep_keyframe, model)
controlnet = load_controlnet(controlnet_path, tk_optional, model)
if is_advanced_controlnet(controlnet):
controlnet.verify_all_weights()
return (controlnet,)
Expand All @@ -91,6 +98,7 @@ def INPUT_TYPES(s):
"weights_override": ("CONTROL_NET_WEIGHTS", ),
"model_optional": ("MODEL",),
"vae_optional": ("VAE",),
"autosize": ("ACNAUTOSIZE", {"padding": 40}),
}
}

Expand Down
13 changes: 10 additions & 3 deletions adv_control/nodes_keyframes.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def INPUT_TYPES(s):
"inherit_missing": ("BOOLEAN", {"default": True}, ),
"guarantee_steps": ("INT", {"default": 1, "min": 0, "max": BIGMAX}),
"mask_optional": ("MASK", ),
"autosize": ("ACNAUTOSIZE", {"padding": 0}),
}
}

Expand Down Expand Up @@ -81,6 +82,7 @@ def INPUT_TYPES(s):
"inherit_missing": ("BOOLEAN", {"default": True},),
"mask_optional": ("MASK", ),
"print_keyframes": ("BOOLEAN", {"default": False}),
"autosize": ("ACNAUTOSIZE", {"padding": 70}),
}
}

Expand Down Expand Up @@ -139,6 +141,7 @@ def INPUT_TYPES(s):
"inherit_missing": ("BOOLEAN", {"default": True},),
"mask_optional": ("MASK", ),
"print_keyframes": ("BOOLEAN", {"default": False}),
"autosize": ("ACNAUTOSIZE", {"padding": 0}),
}
}

Expand Down Expand Up @@ -195,6 +198,7 @@ def INPUT_TYPES(s):
},
"optional": {
"prev_latent_kf": ("LATENT_KEYFRAME", ),
"autosize": ("ACNAUTOSIZE", {"padding": 0}),
}
}

Expand Down Expand Up @@ -230,7 +234,8 @@ def INPUT_TYPES(s):
"optional": {
"prev_latent_kf": ("LATENT_KEYFRAME", ),
"latent_optional": ("LATENT", ),
"print_keyframes": ("BOOLEAN", {"default": False})
"print_keyframes": ("BOOLEAN", {"default": False}),
"autosize": ("ACNAUTOSIZE", {"padding": 35}),
}
}

Expand Down Expand Up @@ -349,7 +354,8 @@ def INPUT_TYPES(s):
},
"optional": {
"prev_latent_kf": ("LATENT_KEYFRAME", ),
"print_keyframes": ("BOOLEAN", {"default": False})
"print_keyframes": ("BOOLEAN", {"default": False}),
"autosize": ("ACNAUTOSIZE", {"padding": 90}),
}
}

Expand Down Expand Up @@ -419,7 +425,8 @@ def INPUT_TYPES(s):
},
"optional": {
"prev_latent_kf": ("LATENT_KEYFRAME", ),
"print_keyframes": ("BOOLEAN", {"default": False})
"print_keyframes": ("BOOLEAN", {"default": False}),
"autosize": ("ACNAUTOSIZE", {"padding": 0}),
}
}

Expand Down
1 change: 1 addition & 0 deletions adv_control/nodes_plusplus.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def INPUT_TYPES(s):
},
"optional": {
"prev_plus_input": ("PLUS_INPUT",),
"autosize": ("ACNAUTOSIZE", {"padding": 0}),
#"strength": ("FLOAT", {"default": 1.0, "min": 0.0, "max": BIGMAX, "step": 0.01}),
}
}
Expand Down
4 changes: 4 additions & 0 deletions adv_control/nodes_sparsectrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ def INPUT_TYPES(s):
"image": ("IMAGE", ),
"vae": ("VAE", ),
"latent_size": ("LATENT", ),
},
"optional": {
"autosize": ("ACNAUTOSIZE", {"padding": 0}),
}
}

Expand Down Expand Up @@ -165,6 +168,7 @@ def INPUT_TYPES(s):
"sparse_hint_mult": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 10.0, "step": 0.001}, ),
"sparse_nonhint_mult": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 10.0, "step": 0.001}, ),
"sparse_mask_mult": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 10.0, "step": 0.001}, ),
"autosize": ("ACNAUTOSIZE", {"padding": 50}),
}
}

Expand Down
7 changes: 7 additions & 0 deletions adv_control/nodes_weight.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def INPUT_TYPES(s):
return {
"optional": {
"cn_extras": ("CN_WEIGHTS_EXTRAS",),
"autosize": ("ACNAUTOSIZE", {"padding": 0}),
}
}

Expand Down Expand Up @@ -41,6 +42,7 @@ def INPUT_TYPES(s):
"optional": {
"uncond_multiplier": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01}, ),
"cn_extras": ("CN_WEIGHTS_EXTRAS",),
"autosize": ("ACNAUTOSIZE", {"padding": 75}),
}
}

Expand Down Expand Up @@ -75,6 +77,7 @@ def INPUT_TYPES(s):
"optional": {
"uncond_multiplier": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01}, ),
"cn_extras": ("CN_WEIGHTS_EXTRAS",),
"autosize": ("ACNAUTOSIZE", {"padding": 20}),
}
}

Expand Down Expand Up @@ -112,6 +115,7 @@ def INPUT_TYPES(s):
"optional": {
"uncond_multiplier": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01}, ),
"cn_extras": ("CN_WEIGHTS_EXTRAS",),
"autosize": ("ACNAUTOSIZE", {"padding": 50}),
}
}

Expand Down Expand Up @@ -153,6 +157,7 @@ def INPUT_TYPES(s):
"optional": {
"uncond_multiplier": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01}, ),
"cn_extras": ("CN_WEIGHTS_EXTRAS",),
"autosize": ("ACNAUTOSIZE", {"padding": 65}),
}
}

Expand Down Expand Up @@ -185,6 +190,7 @@ def INPUT_TYPES(s):
"optional": {
"uncond_multiplier": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01}, ),
"cn_extras": ("CN_WEIGHTS_EXTRAS",),
"autosize": ("ACNAUTOSIZE", {"padding": 55}),
}
}

Expand Down Expand Up @@ -217,6 +223,7 @@ def INPUT_TYPES(s):
"optional": {
"uncond_multiplier": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01}, ),
"cn_extras": ("CN_WEIGHTS_EXTRAS",),
"autosize": ("ACNAUTOSIZE", {"padding": 65}),
}
}

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[project]
name = "comfyui-advanced-controlnet"
description = "Nodes for scheduling ControlNet strength across timesteps and batched latents, as well as applying custom weights and attention masks."
version = "1.1.1"
version = "1.1.2"
license = "LICENSE"
dependencies = []

Expand Down
32 changes: 32 additions & 0 deletions web/js/autosize.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { app } from '../../../scripts/app.js'
app.registerExtension({
name: "AdvancedControlNet.autosize",
async nodeCreated(node) {
if(node.acnAutosize) {
let size = node.computeSize(0);
size[0] += node.acnAutosize?.padding || 0;
node.setSize(size);
}
},
async getCustomWidgets() {
return {
ACNAUTOSIZE(node, inputName, inputData) {
let w = {
name : inputName,
type : "ACN.AUTOSIZE",
value : "",
options : {"serialize": false},
computeSize : function(width) {
return [0, -4];
}
}
node.acnAutosize = inputData[1];
if (!node.widgets) {
node.widgets = []
}
node.widgets.push(w)
return w;
}
}
}
});

0 comments on commit 95d00fc

Please sign in to comment.