Skip to content

Commit

Permalink
add textConcatenate
Browse files Browse the repository at this point in the history
  • Loading branch information
MaraScott committed Sep 23, 2024
1 parent b493e90 commit 77370c5
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 14 deletions.
4 changes: 3 additions & 1 deletion MaraScott_Nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@

from .py.nodes.Bus.AnyBus_v2 import AnyBus_v2
from .py.nodes.Info.DisplayInfo_v2 import DisplayInfo_v2
from .py.nodes.UpscalerRefiner.McBoaty_v2 import UpscalerRefiner_McBoaty_v2
from .py.nodes.UpscalerRefiner.McBoaty_v3 import UpscalerRefiner_McBoaty_v3
from .py.nodes.UpscalerRefiner.McBoaty_v4 import McBoaty_Upscaler_v4, McBoaty_TilePrompter_v4, McBoaty_Refiner_v4
from .py.nodes.UpscalerRefiner.McBoaty_v5 import McBoaty_UpscalerRefiner_v5, McBoaty_Upscaler_v5, McBoaty_TilePrompter_v5, McBoaty_Refiner_v5
from .py.nodes.KSampler.InpaintingTileByMask_v1 import KSampler_setInpaintingTileByMask_v1, KSampler_pasteInpaintingTileByMask_v1
from .py.nodes.Prompt.PromptFromImage_v1 import PromptFromImage_v1
from .py.nodes.Prompt.TextConcatenate_v1 import TextConcatenate_v1
from .py.nodes.Loop.ForLoop_v1 import ForLoopOpen_v1, ForLoopClose_v1, ForLoopWhileOpen_v1, ForLoopWhileClose_v1, ForLoopIntMathOperation_v1, ForLoopToBoolNode_v1
from .py.nodes.Util.Conditional import IsEmpty_v1, IsNone_v1, IsEmptyOrNone_v1, IsEqual_v1
from .py.vendor.ComfyUI_JNodes.blob.main.py.prompting_nodes import TokenCounter as TokenCounter_v1
Expand Down Expand Up @@ -49,6 +49,7 @@
"MaraScottIsEqual_v1": IsEqual_v1,

"MaraScottPromptFromImage_v1": PromptFromImage_v1,
"MaraScottTextConcatenate_v1": TextConcatenate_v1,
"MaraScottDisplayInfo_v2": DisplayInfo_v2,

"MaraScott_Kijai_TokenCounter_v1": TokenCounter_v1,
Expand Down Expand Up @@ -83,6 +84,7 @@
"MaraScottIsEqual_v1": "\ud83d\udc30 Is Equal v1 /c",

"MaraScottPromptFromImage_v1": "\ud83d\udc30 Prompt From Image - McPrompty v1 /p",
"MaraScottTextConcatenate_v1": "\ud83d\udc30 Text Concatenation v1 /t",
"MaraScottAnyBus_v2": "\ud83d\udc30 AnyBus - UniversalBus v2 /*",

"MaraScott_Kijai_TokenCounter_v1": "\ud83d\udc30 TokenCounter (from kijai/ComfyUI-KJNodes) /v",
Expand Down
3 changes: 3 additions & 0 deletions py/inc/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Configuration:
TYPES = {
# Our any instance wants to be a wildcard string
"ANY": AnyType("*"),
"STRING": "STRING",
}

@classmethod
Expand All @@ -39,6 +40,8 @@ def generate_entries(self, input_names, input_types, code = 'py'):
else:
if name.startswith("text"):
entries[name] = (type_, {"forceInput": True, "multiline": True})
elif name.startswith("string"):
entries[name] = (type_, {"forceInput": True})
elif name == "width" or name == "height":
entries[name] = (type_, {"default": 1024, "min": 1, "max": 8192, "forceInput": True})
else:
Expand Down
17 changes: 17 additions & 0 deletions py/inc/profiles/textConcatenate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
#
###

from ..nodes import Configuration as _CONF

class Node:

INPUT_ANY_QTY = 24

INPUT_NAMES = tuple("string {:02d}".format(i) for i in range(1, INPUT_ANY_QTY + 1))

INPUT_TYPES = (_CONF.TYPES['STRING'],) * len(INPUT_NAMES)

ENTRIES = _CONF.generate_entries(INPUT_NAMES, INPUT_TYPES)
ENTRIES_JS = _CONF.generate_entries(INPUT_NAMES, INPUT_TYPES, 'js')
13 changes: 2 additions & 11 deletions py/nodes/Info/DisplayInfo_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,14 @@
#
###
import json
import numpy as np
import torch
from ...utils.helper import AlwaysEqualProxy, AnyType
from ...utils.constants import get_name, get_category
from ...utils.log import log

any_type = AnyType("*")

# Attempt to import numpy and torch, handle if they are not available
try:
import numpy as np
except ImportError:
np = None

try:
import torch
except ImportError:
torch = None

class DisplayInfo_v2:
NAME = get_name('Display Any')

Expand Down
6 changes: 4 additions & 2 deletions py/nodes/Prompt/PromptFromImage_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@

from types import SimpleNamespace

from ...utils.constants import get_name, get_category
from ...inc.lib.llm import MS_Llm

from ...utils.log import log

class PromptFromImage_v1:

NAME = get_name('Prompt from Image')

@classmethod
def INPUT_TYPES(s):
return {
Expand All @@ -35,7 +37,7 @@ def INPUT_TYPES(s):
FUNCTION = "fn"
OUTPUT_NODE = True
OUTPUT_IS_LIST = (False,)
CATEGORY = "MaraScott/Prompt"
CATEGORY = get_category('Prompt')

RETURN_TYPES = (
"STRING",
Expand Down
43 changes: 43 additions & 0 deletions py/nodes/Prompt/TextConcatenate_v1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
#
###
#
# Concatenate up to 24 entries
#
###

from ...inc.profiles.textConcatenate import Node as ProfileNodeTextConcatenate
from ...utils.constants import get_name, get_category

class TextConcatenate_v1:

NAME = get_name('Text Concatenate')

@classmethod
def INPUT_TYPES(s):
return {
"hidden": {"id":"UNIQUE_ID"},
"required": {
"delimiter": ("STRING", { "label": "Delimiter" }),
},
"optional": {
**ProfileNodeTextConcatenate.ENTRIES,
}
}

RETURN_TYPES = ("STRING",)
RETURN_NAMES = ("text",)
FUNCTION = "fn"
CATEGORY = get_category('Prompt')

def fn(self, **kwargs):

delimiter = kwargs.get('delimiter', "")

prefix="string"
filtered_kwargs = {k: v for k, v in kwargs.items() if k.startswith(prefix)}
strings = list(filtered_kwargs.values())
concatenated = delimiter.join(strings)

return (concatenated,)

0 comments on commit 77370c5

Please sign in to comment.