Skip to content

Commit

Permalink
fixed: inversed_switch - If the select is pointing to an out-of-ran…
Browse files Browse the repository at this point in the history
…ge output, remove the input connection instead of the output.

#851 (comment)
  • Loading branch information
ltdrdata committed Dec 19, 2024
1 parent a311f92 commit 8f04714
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion modules/impact/config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import configparser
import os

version_code = [8, 1, 1]
version_code = [8, 1, 2]
version = f"V{version_code[0]}.{version_code[1]}" + (f'.{version_code[2]}' if len(version_code) > 2 else '')

dependency_version = 24
Expand Down
26 changes: 19 additions & 7 deletions modules/impact/impact_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from io import BytesIO
import random
from server import PromptServer
import logging


sam_predictor = None
Expand Down Expand Up @@ -79,7 +80,7 @@ async def sam_prepare(request):

model_name = os.path.join(impact_pack.model_path, "sams", model_name)

print(f"[INFO] ComfyUI-Impact-Pack: Loading SAM model '{impact_pack.model_path}'")
logging.info(f"[Impact Pack] Loading SAM model '{impact_pack.model_path}'")

filename, image_dir = folder_paths.annotated_filepath(data["filename"])

Expand All @@ -95,7 +96,7 @@ async def sam_prepare(request):
thread = threading.Thread(target=async_prepare_sam, args=(image_dir, model_name, filename,))
thread.start()

print(f"[INFO] ComfyUI-Impact-Pack: SAM model loaded. ")
logging.info("[Impact Pack] SAM model loaded. ")
return web.Response(status=200)


Expand All @@ -107,7 +108,7 @@ async def release_sam(request):
del sam_predictor
sam_predictor = None

print(f"[INFO] ComfyUI-Impact-Pack: unloading SAM model")
logging.info("[Impact Pack]: unloading SAM model")


@PromptServer.instance.routes.post("/sam/detect")
Expand Down Expand Up @@ -324,20 +325,24 @@ def onprompt_for_switch(json_data):

cls = v['class_type']
if cls == 'ImpactInversedSwitch':
# if 'sel_mode' is 'select_on_prompt'
if 'sel_mode' in v['inputs'] and v['inputs']['sel_mode'] and 'select' in v['inputs']:
select_input = v['inputs']['select']
# if 'select' is converted input
if isinstance(select_input, list) and len(select_input) == 2:
input_node = json_data['prompt'][select_input[0]]
if input_node['class_type'] == 'ImpactInt' and 'inputs' in input_node and 'value' in input_node['inputs']:
inversed_switch_info[k] = input_node['inputs']['value']
else:
print(f"\n##### ##### #####\n[WARN] {cls}: For the 'select' operation, only 'select_index' of the 'ImpactInversedSwitch', which is not an input, or 'ImpactInt' and 'Primitive' are allowed as inputs if 'select_on_prompt' is selected.\n##### ##### #####\n")
logging.warning(f"\n##### ##### #####\n[Impact Pack] {cls}: For the 'select' operation, only 'select_index' of the 'ImpactInversedSwitch', which is not an input, or 'ImpactInt' and 'Primitive' are allowed as inputs if 'select_on_prompt' is selected.\n##### ##### #####\n")
else:
inversed_switch_info[k] = select_input

elif cls in ['ImpactSwitch', 'LatentSwitch', 'SEGSSwitch', 'ImpactMakeImageList']:
# if 'sel_mode' is 'select_on_prompt'
if 'sel_mode' in v['inputs'] and v['inputs']['sel_mode'] and 'select' in v['inputs']:
select_input = v['inputs']['select']
# if 'select' is converted input
if isinstance(select_input, list) and len(select_input) == 2:
input_node = json_data['prompt'][select_input[0]]
if input_node['class_type'] == 'ImpactInt' and 'inputs' in input_node and 'value' in input_node['inputs']:
Expand All @@ -346,7 +351,7 @@ def onprompt_for_switch(json_data):
if isinstance(input_node['inputs']['select'], int):
onprompt_switch_info[k] = input_node['inputs']['select']
else:
print(f"\n##### ##### #####\n[WARN] {cls}: For the 'select' operation, only 'select_index' of the 'ImpactSwitch', which is not an input, or 'ImpactInt' and 'Primitive' are allowed as inputs if 'select_on_prompt' is selected.\n##### ##### #####\n")
logging.warning(f"\n##### ##### #####\n[Impact Pack] {cls}: For the 'select' operation, only 'select_index' of the 'ImpactSwitch', which is not an input, or 'ImpactInt' and 'Primitive' are allowed as inputs if 'select_on_prompt' is selected.\n##### ##### #####\n")
else:
onprompt_switch_info[k] = select_input

Expand Down Expand Up @@ -377,6 +382,8 @@ def onprompt_for_switch(json_data):
if vv[0] in inversed_switch_info:
if vv[1] + 1 != inversed_switch_info[vv[0]]:
disable_targets.add(kk)
else:
del inversed_switch_info[k]

if vv[0] in disabled_switch:
disable_targets.add(kk)
Expand All @@ -396,6 +403,11 @@ def onprompt_for_switch(json_data):
for kk in disable_targets:
del v['inputs'][kk]

# inversed_switch - select out of range
for target in inversed_switch_info.keys():
del json_data['prompt'][target]['inputs']['input']


def onprompt_for_pickers(json_data):
detected_pickers = set()

Expand Down Expand Up @@ -479,7 +491,7 @@ def onprompt_populate_wildcards(json_data):
if not isinstance(input_seed, int):
continue
else:
print(f"[Impact Pack] Only `ImpactInt`, `Seed (rgthree)` and `Primitive` Node are allowed as the seed for '{v['class_type']}'. It will be ignored. ")
logging.info(f"[Impact Pack] Only `ImpactInt`, `Seed (rgthree)` and `Primitive` Node are allowed as the seed for '{v['class_type']}'. It will be ignored. ")
continue
except:
continue
Expand Down Expand Up @@ -542,7 +554,7 @@ def onprompt(json_data):
regional_sampler_seed_update(json_data)
core.current_prompt = json_data
except Exception as e:
print(f"[WARN] ComfyUI-Impact-Pack: Error on prompt - several features will not work.\n{e}")
logging.warning(f"[Impact Pack] ComfyUI-Impact-Pack: Error on prompt - several features will not work.\n{e}")

return json_data

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-impact-pack"
description = "This node pack offers various detector nodes and detailer nodes that allow you to configure a workflow that automatically enhances facial details. And provide iterative upscaler."
version = "8.1.1"
version = "8.1.2"
license = { file = "LICENSE.txt" }
dependencies = ["segment-anything", "scikit-image", "piexif", "transformers", "opencv-python-headless", "GitPython", "scipy>=1.11.4"]

Expand Down

0 comments on commit 8f04714

Please sign in to comment.