Skip to content

Commit

Permalink
Merge pull request #122 from Kosinkadink/develop
Browse files Browse the repository at this point in the history
Add automatic workaround for outdated Steerable-Motion workflow issue
  • Loading branch information
Kosinkadink committed Jun 13, 2024
2 parents f6adc32 + fa870f6 commit bf16347
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
24 changes: 24 additions & 0 deletions adv_control/control_sparsectrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@ class SparseContextAware:
class SparseSettings:
def __init__(self, sparse_method: 'SparseMethod', use_motion: bool=True, motion_strength=1.0, motion_scale=1.0, merged=False,
sparse_mask_mult=1.0, sparse_hint_mult=1.0, sparse_nonhint_mult=1.0, context_aware=SparseContextAware.NEAREST_HINT):
# account for Steerable-Motion workflow incompatibility;
# doing this to for my own peace of mind (not an issue with my code)
if type(sparse_method) == str:
logger.warn("Outdated Steerable-Motion workflow detected; attempting to auto-convert indexes input. If you experience an error here, consult Steerable-Motion github, NOT Advanced-ControlNet.")
sparse_method = SparseIndexMethod(get_idx_list_from_str(sparse_method))
self.sparse_method = sparse_method
self.use_motion = use_motion
self.motion_strength = motion_strength
Expand Down Expand Up @@ -356,6 +361,25 @@ def _get_indexes(self, hint_length: int, full_length: int) -> list[int]:
return new_idxs


def get_idx_list_from_str(indexes: str) -> list[int]:
idxs = []
unique_idxs = set()
# get indeces from string
str_idxs = [x.strip() for x in indexes.strip().split(",")]
for str_idx in str_idxs:
try:
idx = int(str_idx)
if idx in unique_idxs:
raise ValueError(f"'{idx}' is duplicated; indexes must be unique.")
idxs.append(idx)
unique_idxs.add(idx)
except ValueError:
raise ValueError(f"'{str_idx}' is not a valid integer index.")
if len(idxs) == 0:
raise ValueError(f"No indexes were listed in Sparse Index Method.")
return idxs


#########################################
# motion-related portion of controlnet
class BlockType:
Expand Down
18 changes: 2 additions & 16 deletions adv_control/nodes_sparsectrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from comfy.sd import VAE

from .utils import TimestepKeyframeGroup
from .control_sparsectrl import SparseMethod, SparseIndexMethod, SparseSettings, SparseSpreadMethod, PreprocSparseRGBWrapper, SparseConst, SparseContextAware
from .control_sparsectrl import SparseMethod, SparseIndexMethod, SparseSettings, SparseSpreadMethod, PreprocSparseRGBWrapper, SparseConst, SparseContextAware, get_idx_list_from_str
from .control import load_sparsectrl, load_controlnet, ControlNetAdvanced, SparseCtrlAdvanced


Expand Down Expand Up @@ -103,21 +103,7 @@ def INPUT_TYPES(s):
CATEGORY = "Adv-ControlNet 🛂🅐🅒🅝/SparseCtrl"

def get_method(self, indexes: str):
idxs = []
unique_idxs = set()
# get indeces from string
str_idxs = [x.strip() for x in indexes.strip().split(",")]
for str_idx in str_idxs:
try:
idx = int(str_idx)
if idx in unique_idxs:
raise ValueError(f"'{idx}' is duplicated; indexes must be unique.")
idxs.append(idx)
unique_idxs.add(idx)
except ValueError:
raise ValueError(f"'{str_idx}' is not a valid integer index.")
if len(idxs) == 0:
raise ValueError(f"No indexes were listed in Sparse Index Method.")
idxs = get_idx_list_from_str(indexes)
return (SparseIndexMethod(idxs),)


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.0.4"
version = "1.0.5"
license = "LICENSE"
dependencies = []

Expand Down

0 comments on commit bf16347

Please sign in to comment.