Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
38eb65df2e | ||
|
|
391706aa63 | ||
|
|
4f04f339d3 | ||
|
|
4b4f14232b | ||
|
|
2e73885a85 | ||
|
|
aba975a53e | ||
|
|
6c2e42ff26 | ||
|
|
b1f7d794e8 | ||
|
|
c4390b808b | ||
|
|
19df97c09f | ||
|
|
e23de0e693 | ||
|
|
2e6dadb296 | ||
|
|
da4c63d3d4 | ||
|
|
73348a6034 | ||
|
|
0a4313e4c3 | ||
|
|
8ddf1a4c77 | ||
|
|
44b4952dc8 | ||
|
|
512e2d40f3 | ||
|
|
720ff188cc | ||
|
|
6a12858acc | ||
|
|
64d856dab6 | ||
|
|
9ac320b50b | ||
|
|
83f12f1389 | ||
|
|
d4e2312d6c | ||
|
|
711fdb6a33 | ||
|
|
28f903d0d1 |
@@ -0,0 +1,15 @@
|
||||
# Declare files that always have LF line endings on checkout
|
||||
* text eol=lf
|
||||
|
||||
# Denote all files that are truly binary and should not be modified
|
||||
*.bin binary
|
||||
*.heif binary
|
||||
*.heic binary
|
||||
*.hif binary
|
||||
*.avif binary
|
||||
*.png binary
|
||||
*.gif binary
|
||||
*.webp binary
|
||||
*.tiff binary
|
||||
*.jpeg binary
|
||||
*.jpg binary
|
||||
@@ -0,0 +1,26 @@
|
||||
name: Publish to Comfy registry
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- master
|
||||
paths:
|
||||
- "pyproject.toml"
|
||||
|
||||
permissions:
|
||||
issues: write
|
||||
|
||||
jobs:
|
||||
publish-node:
|
||||
name: Publish Custom Node to registry
|
||||
runs-on: ubuntu-latest
|
||||
if: ${{ github.repository_owner == 'Visionatrix' }}
|
||||
steps:
|
||||
- name: Check out code
|
||||
uses: actions/checkout@v4
|
||||
- name: Publish Custom Node
|
||||
uses: Comfy-Org/publish-node-action@v1
|
||||
with:
|
||||
## Add your own personal access token to your Github Repository secrets and reference it here.
|
||||
personal_access_token: ${{ secrets.REGISTRY_ACCESS_TOKEN }}
|
||||
@@ -0,0 +1,32 @@
|
||||
exclude: ^(screenshots)/
|
||||
repos:
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v5.0.0
|
||||
hooks:
|
||||
- id: check-yaml
|
||||
- id: check-toml
|
||||
- id: end-of-file-fixer
|
||||
- id: trailing-whitespace
|
||||
- id: mixed-line-ending
|
||||
|
||||
- repo: https://github.com/PyCQA/isort
|
||||
rev: 6.0.1
|
||||
hooks:
|
||||
- id: isort
|
||||
files: .
|
||||
|
||||
- repo: https://github.com/psf/black
|
||||
rev: 25.1.0
|
||||
hooks:
|
||||
- id: black
|
||||
files: .
|
||||
|
||||
- repo: https://github.com/tox-dev/pyproject-fmt
|
||||
rev: v2.5.1
|
||||
hooks:
|
||||
- id: pyproject-fmt
|
||||
|
||||
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||
rev: v0.11.2
|
||||
hooks:
|
||||
- id: ruff
|
||||
@@ -17,3 +17,19 @@ Current `Visionatrix/UI` nodes list:
|
||||
- **VixUi-CheckboxLogic** - to define the boolean logical switch (checkbox), e.g. two modes and paths of workflow execution;
|
||||
- **VixUi-ListLogic** - to define the list of available mode options similar to `VixUi-CheckboxLogic` (up to 6 input options);
|
||||
- **VixUi-WorkflowMetadata** - mandatory node to fill the workflow metadata required for each Visionatrix flow for displaying in the UI list of workflows;
|
||||
- **VixUiAspectRatioSelector** - use it to display the desired image aspect ratio for your Flow.
|
||||
|
||||
Current `Visionatrix/Text` nodes list:
|
||||
|
||||
- **VixDictionaryNew** - create a dictionary with up to 9 keys.
|
||||
- **VixDictionaryConvert** - node to create dictionary from text.
|
||||
- **VixDictionaryGet** - node to get value by key from dictionary.
|
||||
- **VixDictionaryUpdate** - update one dictionary with values from another dictionary.
|
||||
|
||||
Current `Visionatrix/Image` nodes list:
|
||||
|
||||
- **VixImageFilters** - applies brightness, saturation, sharpness and other simple Pillow filters to an image.
|
||||
|
||||
### Incorporated nodes
|
||||
|
||||
- **StyleAlignedBatchAlign** - from the `style_aligned_comfy` repository
|
||||
|
||||
+2
-337
@@ -1,338 +1,3 @@
|
||||
import json
|
||||
from .nodes import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS
|
||||
|
||||
|
||||
class AnyType(str):
|
||||
def __ne__(self, __value: object) -> bool:
|
||||
return False
|
||||
|
||||
|
||||
any_typ = AnyType("*")
|
||||
|
||||
|
||||
class VixUiCheckbox:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"state": ("BOOLEAN", {"default": False}),
|
||||
"display_name": ("STRING", {"default": "Display Name"}),
|
||||
"optional": ("BOOLEAN", {"default": True}),
|
||||
"advanced": ("BOOLEAN", {"default": True}),
|
||||
"order": ("INT", {"default": 99}),
|
||||
"custom_id": ("STRING", {"default": ""}),
|
||||
},
|
||||
"optional": {
|
||||
"hidden": ("BOOLEAN", {"default": False}),
|
||||
},
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("BOOLEAN", "INT")
|
||||
RETURN_NAMES = ("bool", "int")
|
||||
CATEGORY = "Visionatrix/UI"
|
||||
FUNCTION = "do_it"
|
||||
|
||||
@classmethod
|
||||
def do_it(cls, state, **kwargs) -> tuple:
|
||||
return state, int(state)
|
||||
|
||||
|
||||
class VixUiRangeFloat:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"value": ("FLOAT", {"default": 4.0, "step": 0.01, "round": False}),
|
||||
"display_name": ("STRING", {"default": "Display Range"}),
|
||||
"optional": ("BOOLEAN", {"default": True}),
|
||||
"advanced": ("BOOLEAN", {"default": True}),
|
||||
"min": ("FLOAT", {"default": 1.0, "step": 0.01, "round": False}),
|
||||
"max": ("FLOAT", {"default": 9.0, "step": 0.01, "round": False}),
|
||||
"step": ("FLOAT", {"default": 0.1, "step": 0.01, "round": False}),
|
||||
"order": ("INT", {"default": 99}),
|
||||
"custom_id": ("STRING", {"default": ""}),
|
||||
},
|
||||
"optional": {
|
||||
"hidden": ("BOOLEAN", {"default": False}),
|
||||
},
|
||||
}
|
||||
|
||||
FUNCTION = "do_it"
|
||||
CATEGORY = "Visionatrix/UI"
|
||||
RETURN_TYPES = ("FLOAT",)
|
||||
|
||||
@classmethod
|
||||
def do_it(cls, value, **kwargs) -> tuple:
|
||||
return (value,)
|
||||
|
||||
|
||||
class VixUiRangeScaleFloat:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"value": ("FLOAT", {"default": 4.0, "step": 0.01, "round": False}),
|
||||
"display_name": ("STRING", {"default": "Image Size Factor"}),
|
||||
"optional": ("BOOLEAN", {"default": True}),
|
||||
"advanced": ("BOOLEAN", {"default": True}),
|
||||
"source_input_name": ("STRING", {"default": ""}),
|
||||
"min": ("FLOAT", {"default": 1.0, "step": 0.01, "round": False}),
|
||||
"max": ("FLOAT", {"default": 9.0, "step": 0.01, "round": False}),
|
||||
"step": ("FLOAT", {"default": 0.1, "step": 0.01, "round": False}),
|
||||
"order": ("INT", {"default": 99}),
|
||||
"custom_id": ("STRING", {"default": ""}),
|
||||
},
|
||||
"optional": {
|
||||
"hidden": ("BOOLEAN", {"default": False}),
|
||||
},
|
||||
}
|
||||
|
||||
FUNCTION = "do_it"
|
||||
CATEGORY = "Visionatrix/UI"
|
||||
RETURN_TYPES = ("FLOAT",)
|
||||
|
||||
@classmethod
|
||||
def do_it(cls, value, **kwargs) -> tuple:
|
||||
return (value,)
|
||||
|
||||
|
||||
class VixUiRangeInt:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"value": ("INT", {"default": 10}),
|
||||
"display_name": ("STRING", {"default": "Display Range"}),
|
||||
"optional": ("BOOLEAN", {"default": True}),
|
||||
"advanced": ("BOOLEAN", {"default": True}),
|
||||
"min": ("INT", {"default": 1}),
|
||||
"max": ("INT", {"default": 20}),
|
||||
"step": ("INT", {"default": 1}),
|
||||
"order": ("INT", {"default": 99}),
|
||||
"custom_id": ("STRING", {"default": ""}),
|
||||
},
|
||||
"optional": {
|
||||
"hidden": ("BOOLEAN", {"default": False}),
|
||||
},
|
||||
}
|
||||
|
||||
FUNCTION = "do_it"
|
||||
CATEGORY = "Visionatrix/UI"
|
||||
RETURN_TYPES = ("INT",)
|
||||
|
||||
@classmethod
|
||||
def do_it(cls, value, **kwargs) -> tuple:
|
||||
return (value,)
|
||||
|
||||
|
||||
class VixUiList:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"default_value": ("STRING", {}),
|
||||
"possible_values": ("STRING", {"default": "[]", "multiline": True}),
|
||||
"display_name": ("STRING", {"default": "Dropdown list"}),
|
||||
"optional": ("BOOLEAN", {"default": True}),
|
||||
"advanced": ("BOOLEAN", {"default": True}),
|
||||
"order": ("INT", {"default": 99}),
|
||||
"custom_id": ("STRING", {"default": ""}),
|
||||
},
|
||||
"optional": {
|
||||
"hidden": ("BOOLEAN", {"default": False}),
|
||||
},
|
||||
}
|
||||
RETURN_TYPES = (any_typ,)
|
||||
FUNCTION = "do_it"
|
||||
CATEGORY = "Visionatrix/UI"
|
||||
|
||||
@classmethod
|
||||
def do_it(cls, default_value, **kwargs) -> tuple:
|
||||
possible_values = json.loads(kwargs["possible_values"])
|
||||
if isinstance(possible_values, dict) and default_value in possible_values:
|
||||
return (possible_values[default_value],)
|
||||
return (default_value,)
|
||||
|
||||
|
||||
class VixUiPrompt:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"text": ("STRING", {"default": "", "multiline": True, "dynamicPrompts": True}),
|
||||
"display_name": ("STRING", {"default": "Prompt"}),
|
||||
"optional": ("BOOLEAN", {"default": False}),
|
||||
"advanced": ("BOOLEAN", {"default": False}),
|
||||
"order": ("INT", {"default": 10}),
|
||||
"custom_id": ("STRING", {"default": ""}),
|
||||
},
|
||||
"optional": {
|
||||
"hidden": ("BOOLEAN", {"default": False}),
|
||||
"translatable": ("BOOLEAN", {"default": False}),
|
||||
},
|
||||
}
|
||||
RETURN_TYPES = ("STRING",)
|
||||
FUNCTION = "do_it"
|
||||
CATEGORY = "Visionatrix/UI"
|
||||
|
||||
@classmethod
|
||||
def do_it(cls, text, **kwargs) -> tuple:
|
||||
return (text,)
|
||||
|
||||
|
||||
class VixUiCheckboxLogic:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"state": ("BOOLEAN", {"default": False}),
|
||||
"display_name": ("STRING", {"default": "Display Name"}),
|
||||
"optional": ("BOOLEAN", {"default": True}),
|
||||
"advanced": ("BOOLEAN", {"default": True}),
|
||||
"order": ("INT", {"default": 99}),
|
||||
"custom_id": ("STRING", {"default": ""}),
|
||||
},
|
||||
"optional": {
|
||||
"input_off_state": (any_typ, {"lazy": True}),
|
||||
"input_on_state": (any_typ, {"lazy": True}),
|
||||
"hidden": ("BOOLEAN", {"default": False}),
|
||||
},
|
||||
}
|
||||
|
||||
RETURN_TYPES = (any_typ,)
|
||||
RETURN_NAMES = ("output_to",)
|
||||
CATEGORY = "Visionatrix/UI"
|
||||
FUNCTION = "do_it"
|
||||
|
||||
@classmethod
|
||||
def do_it(cls, state, **kwargs) -> tuple:
|
||||
if state is False:
|
||||
return (kwargs.get("input_off_state", None),)
|
||||
return (kwargs.get("input_on_state", None),)
|
||||
|
||||
@staticmethod
|
||||
def check_lazy_status(state, **kwargs):
|
||||
if state is False:
|
||||
return ["input_off_state"]
|
||||
return ["input_on_state"]
|
||||
|
||||
|
||||
class VixUiListLogic:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"default_value": ("STRING", {}),
|
||||
"possible_values": ("STRING", {"default": "[]", "multiline": True}),
|
||||
"display_name": ("STRING", {"default": "Display Name"}),
|
||||
"optional": ("BOOLEAN", {"default": True}),
|
||||
"advanced": ("BOOLEAN", {"default": True}),
|
||||
"order": ("INT", {"default": 99}),
|
||||
"custom_id": ("STRING", {"default": ""}),
|
||||
},
|
||||
"optional": {
|
||||
"input_first": (any_typ, {"lazy": True}),
|
||||
"input_second": (any_typ, {"lazy": True}),
|
||||
"input_third": (any_typ, {"lazy": True}),
|
||||
"input_fourth": (any_typ, {"lazy": True}),
|
||||
"input_fifth": (any_typ, {"lazy": True}),
|
||||
"input_sixth": (any_typ, {"lazy": True}),
|
||||
"hidden": ("BOOLEAN", {"default": False}),
|
||||
},
|
||||
}
|
||||
|
||||
RETURN_TYPES = (any_typ,)
|
||||
RETURN_NAMES = ("output_to",)
|
||||
CATEGORY = "Visionatrix/UI"
|
||||
FUNCTION = "do_it"
|
||||
|
||||
@classmethod
|
||||
def do_it(cls, default_value, **kwargs) -> tuple:
|
||||
list_with_values: list = json.loads(kwargs["possible_values"])
|
||||
index_to_return = list_with_values.index(default_value)
|
||||
if index_to_return == 0:
|
||||
return (kwargs["input_first"],)
|
||||
if index_to_return == 1:
|
||||
return (kwargs["input_second"],)
|
||||
if index_to_return == 2:
|
||||
return (kwargs["input_third"],)
|
||||
if index_to_return == 3:
|
||||
return (kwargs["input_fourth"],)
|
||||
if index_to_return == 4:
|
||||
return (kwargs["input_fifth"],)
|
||||
if index_to_return == 5:
|
||||
return (kwargs["input_sixth"],)
|
||||
raise RuntimeError("Workflow logic error")
|
||||
|
||||
@staticmethod
|
||||
def check_lazy_status(default_value, **kwargs):
|
||||
list_with_values: list = json.loads(kwargs["possible_values"])
|
||||
index_to_return = list_with_values.index(default_value)
|
||||
if index_to_return == 0:
|
||||
return ["input_first"]
|
||||
if index_to_return == 1:
|
||||
return ["input_second"]
|
||||
if index_to_return == 2:
|
||||
return ["input_third"]
|
||||
if index_to_return == 3:
|
||||
return ["input_fourth"]
|
||||
if index_to_return == 4:
|
||||
return ["input_fifth"]
|
||||
if index_to_return == 5:
|
||||
return ["input_sixth"]
|
||||
raise RuntimeError("Workflow logic error")
|
||||
|
||||
|
||||
class VixUiWorkflowMetadata:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"name": ("STRING", {}),
|
||||
"display_name": ("STRING", {}),
|
||||
"description": ("STRING", {"default": ""}),
|
||||
"author": ("STRING", {}),
|
||||
"homepage": ("STRING", {"default": ""}),
|
||||
"documentation": ("STRING", {"default": ""}),
|
||||
"license": ("STRING", {"default": ""}),
|
||||
"tags": ("STRING", {"default": "[\"general\"]", "multiline": True}),
|
||||
"version": ("STRING", {"default": "1.0.0"})
|
||||
},
|
||||
"optional": {
|
||||
"requires": ("STRING", {"default": "[]", "multiline": True}),
|
||||
"is_seed_supported": ("BOOLEAN", {"default": True}),
|
||||
"is_count_supported": ("BOOLEAN", {"default": True}),
|
||||
"is_translations_supported": ("BOOLEAN", {"default": False}),
|
||||
}
|
||||
}
|
||||
RETURN_TYPES = ("STRING",)
|
||||
FUNCTION = "do_it"
|
||||
CATEGORY = "Visionatrix/UI"
|
||||
|
||||
@classmethod
|
||||
def do_it(cls, text, **kwargs) -> tuple:
|
||||
return (text,)
|
||||
|
||||
|
||||
NODE_CLASS_MAPPINGS = {
|
||||
"VixUiCheckbox": VixUiCheckbox,
|
||||
"VixUiRangeFloat": VixUiRangeFloat,
|
||||
"VixUiRangeScaleFloat": VixUiRangeScaleFloat,
|
||||
"VixUiRangeInt": VixUiRangeInt,
|
||||
"VixUiList": VixUiList,
|
||||
"VixUiPrompt": VixUiPrompt,
|
||||
"VixUiCheckboxLogic": VixUiCheckboxLogic,
|
||||
"VixUiListLogic": VixUiListLogic,
|
||||
"VixUiWorkflowMetadata": VixUiWorkflowMetadata,
|
||||
}
|
||||
|
||||
NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"VixUiCheckbox": "VixUI-Checkbox",
|
||||
"VixUiRangeFloat": "VixUI-RangeFloat",
|
||||
"VixUiRangeScaleFloat": "VixUI-RangeScaleFloat",
|
||||
"VixUiRangeInt": "VixUI-RangeInt",
|
||||
"VixUiList": "VixUI-List",
|
||||
"VixUiPrompt": "VixUI-Prompt",
|
||||
"VixUiCheckboxLogic": "VixUI-CheckboxLogic",
|
||||
"VixUiListLogic": "VixUI-ListLogic",
|
||||
"VixUiWorkflowMetadata": "VixUI-WorkflowMetadata",
|
||||
}
|
||||
__all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS"]
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
import numpy as np
|
||||
import torch
|
||||
from PIL import Image, ImageEnhance, ImageFilter
|
||||
|
||||
from .utils import image_to_pillow, pillow_to_image
|
||||
|
||||
|
||||
class VixImageFilters:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"image": ("IMAGE",),
|
||||
"brightness": (
|
||||
"FLOAT",
|
||||
{"default": 0.0, "min": -1.0, "max": 1.0, "step": 0.01},
|
||||
),
|
||||
"contrast": (
|
||||
"FLOAT",
|
||||
{"default": 1.0, "min": -1.0, "max": 2.0, "step": 0.01},
|
||||
),
|
||||
"saturation": (
|
||||
"FLOAT",
|
||||
{"default": 1.0, "min": 0.0, "max": 5.0, "step": 0.01},
|
||||
),
|
||||
"sharpness": (
|
||||
"FLOAT",
|
||||
{"default": 1.0, "min": -5.0, "max": 5.0, "step": 0.01},
|
||||
),
|
||||
"blur": ("INT", {"default": 0, "min": 0, "max": 16, "step": 1}),
|
||||
"gaussian_blur": (
|
||||
"FLOAT",
|
||||
{"default": 0.0, "min": 0.0, "max": 1024.0, "step": 0.1},
|
||||
),
|
||||
"edge_enhance": (
|
||||
"FLOAT",
|
||||
{"default": 0.0, "min": 0.0, "max": 1.0, "step": 0.01},
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("IMAGE",)
|
||||
FUNCTION = "do_it"
|
||||
CATEGORY = "Visionatrix/Image"
|
||||
|
||||
@classmethod
|
||||
def process_image(
|
||||
cls,
|
||||
img: torch.Tensor,
|
||||
brightness: float,
|
||||
contrast: float,
|
||||
saturation: float,
|
||||
sharpness: float,
|
||||
blur: int,
|
||||
gaussian_blur: float,
|
||||
edge_enhance: float,
|
||||
processing_list: bool = False,
|
||||
) -> torch.Tensor:
|
||||
img = np.clip(img + brightness, 0.0, 1.0) if brightness != 0.0 else img
|
||||
img = np.clip(img * contrast, 0.0, 1.0) if contrast != 1.0 else img
|
||||
|
||||
pil_image = None
|
||||
|
||||
if saturation != 1.0:
|
||||
pil_image = ImageEnhance.Color(image_to_pillow(img)).enhance(saturation)
|
||||
|
||||
if sharpness != 1.0:
|
||||
pil_image = ImageEnhance.Sharpness(pil_image or image_to_pillow(img)).enhance(sharpness)
|
||||
|
||||
if blur > 0:
|
||||
pil_image = pil_image or image_to_pillow(img)
|
||||
for _ in range(blur):
|
||||
pil_image = pil_image.filter(ImageFilter.BLUR)
|
||||
|
||||
if gaussian_blur > 0.0:
|
||||
pil_image = pil_image or image_to_pillow(img)
|
||||
pil_image = pil_image.filter(ImageFilter.GaussianBlur(radius=gaussian_blur))
|
||||
|
||||
if edge_enhance > 0.0:
|
||||
pil_image = pil_image or image_to_pillow(img)
|
||||
edge_enhanced = pil_image.filter(ImageFilter.EDGE_ENHANCE_MORE)
|
||||
mask = Image.new("L", pil_image.size, color=round(edge_enhance * 255))
|
||||
pil_image = Image.composite(edge_enhanced, pil_image, mask)
|
||||
|
||||
return pillow_to_image(pil_image) if pil_image else (img.unsqueeze(0) if processing_list else img)
|
||||
|
||||
def do_it(
|
||||
self,
|
||||
image: torch.Tensor | list[torch.Tensor],
|
||||
brightness: float,
|
||||
contrast: float,
|
||||
saturation: float,
|
||||
sharpness: float,
|
||||
blur: int,
|
||||
gaussian_blur: float,
|
||||
edge_enhance: float,
|
||||
):
|
||||
if len(image) > 1:
|
||||
result = [
|
||||
self.process_image(
|
||||
img,
|
||||
brightness,
|
||||
contrast,
|
||||
saturation,
|
||||
sharpness,
|
||||
blur,
|
||||
gaussian_blur,
|
||||
edge_enhance,
|
||||
processing_list=True,
|
||||
)
|
||||
for img in image
|
||||
]
|
||||
return (torch.cat(result, dim=0),)
|
||||
return (
|
||||
self.process_image(
|
||||
image,
|
||||
brightness,
|
||||
contrast,
|
||||
saturation,
|
||||
sharpness,
|
||||
blur,
|
||||
gaussian_blur,
|
||||
edge_enhance,
|
||||
),
|
||||
)
|
||||
@@ -0,0 +1,490 @@
|
||||
import json
|
||||
|
||||
from . import image, text
|
||||
from .style_aligned import StyleAlignedBatchAlign
|
||||
|
||||
|
||||
class AnyType(str):
|
||||
def __ne__(self, __value: object) -> bool:
|
||||
return False
|
||||
|
||||
|
||||
any_typ = AnyType("*")
|
||||
|
||||
|
||||
class VixUiAspectRatioSelector:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {
|
||||
"required": {
|
||||
"aspect_ratio": (
|
||||
[
|
||||
"1:1 (1024x1024)",
|
||||
"2:3 (832x1216)",
|
||||
"3:4 (896x1152)",
|
||||
"5:8 (768x1216)",
|
||||
"9:16 (768x1344)",
|
||||
"9:19 (704x1472)",
|
||||
"9:21 (640x1536)",
|
||||
"3:2 (1216x832)",
|
||||
"4:3 (1152x896)",
|
||||
"8:5 (1216x768)",
|
||||
"16:9 (1344x768)",
|
||||
"20:11 (1280x704)",
|
||||
"19:9 (1472x704)",
|
||||
"21:9 (1536x640)",
|
||||
],
|
||||
),
|
||||
"display_name": ("STRING", {"default": "Aspect Ratio"}),
|
||||
"optional": ("BOOLEAN", {"default": True}),
|
||||
"advanced": ("BOOLEAN", {"default": True}),
|
||||
"order": ("INT", {"default": 20}),
|
||||
"custom_id": ("STRING", {"default": "aspect_ratio"}),
|
||||
},
|
||||
"optional": {
|
||||
"hidden": ("BOOLEAN", {"default": False}),
|
||||
},
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("STRING", "INT", "INT")
|
||||
RETURN_NAMES = ("ratio", "width", "height")
|
||||
FUNCTION = "do_it"
|
||||
CATEGORY = "Visionatrix/UI"
|
||||
|
||||
def do_it(self, aspect_ratio, **kwargs):
|
||||
ratio, dims = aspect_ratio.split(" (")
|
||||
dims = dims[:-1] # Remove the closing parenthesis
|
||||
width, height = map(int, dims.split("x"))
|
||||
return ratio, width, height
|
||||
|
||||
|
||||
class VixUiCheckbox:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"state": ("BOOLEAN", {"default": False}),
|
||||
"display_name": ("STRING", {"default": "Display Name"}),
|
||||
"optional": ("BOOLEAN", {"default": True}),
|
||||
"advanced": ("BOOLEAN", {"default": True}),
|
||||
"order": ("INT", {"default": 99}),
|
||||
"custom_id": ("STRING", {"default": ""}),
|
||||
},
|
||||
"optional": {
|
||||
"hidden": ("BOOLEAN", {"default": False}),
|
||||
},
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("BOOLEAN", "INT")
|
||||
RETURN_NAMES = ("bool", "int")
|
||||
CATEGORY = "Visionatrix/UI"
|
||||
FUNCTION = "do_it"
|
||||
|
||||
@classmethod
|
||||
def do_it(cls, state, **kwargs) -> tuple:
|
||||
return state, int(state)
|
||||
|
||||
|
||||
class VixUiRangeFloat:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"value": ("FLOAT", {"default": 4.0, "step": 0.01, "round": False}),
|
||||
"display_name": ("STRING", {"default": "Display Range"}),
|
||||
"optional": ("BOOLEAN", {"default": True}),
|
||||
"advanced": ("BOOLEAN", {"default": True}),
|
||||
"min": ("FLOAT", {"default": 1.0, "step": 0.01, "round": False}),
|
||||
"max": ("FLOAT", {"default": 9.0, "step": 0.01, "round": False}),
|
||||
"step": ("FLOAT", {"default": 0.1, "step": 0.01, "round": False}),
|
||||
"order": ("INT", {"default": 99}),
|
||||
"custom_id": ("STRING", {"default": ""}),
|
||||
},
|
||||
"optional": {
|
||||
"hidden": ("BOOLEAN", {"default": False}),
|
||||
},
|
||||
}
|
||||
|
||||
FUNCTION = "do_it"
|
||||
CATEGORY = "Visionatrix/UI"
|
||||
RETURN_TYPES = ("FLOAT",)
|
||||
|
||||
@classmethod
|
||||
def do_it(cls, value, **kwargs) -> tuple:
|
||||
return (value,)
|
||||
|
||||
|
||||
class VixUiRangeScaleFloat:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"value": ("FLOAT", {"default": 4.0, "step": 0.01, "round": False}),
|
||||
"display_name": ("STRING", {"default": "Image Size Factor"}),
|
||||
"optional": ("BOOLEAN", {"default": True}),
|
||||
"advanced": ("BOOLEAN", {"default": True}),
|
||||
"source_input_name": ("STRING", {"default": ""}),
|
||||
"min": ("FLOAT", {"default": 1.0, "step": 0.01, "round": False}),
|
||||
"max": ("FLOAT", {"default": 9.0, "step": 0.01, "round": False}),
|
||||
"step": ("FLOAT", {"default": 0.1, "step": 0.01, "round": False}),
|
||||
"order": ("INT", {"default": 99}),
|
||||
"custom_id": ("STRING", {"default": ""}),
|
||||
},
|
||||
"optional": {
|
||||
"hidden": ("BOOLEAN", {"default": False}),
|
||||
},
|
||||
}
|
||||
|
||||
FUNCTION = "do_it"
|
||||
CATEGORY = "Visionatrix/UI"
|
||||
RETURN_TYPES = ("FLOAT",)
|
||||
|
||||
@classmethod
|
||||
def do_it(cls, value, **kwargs) -> tuple:
|
||||
return (value,)
|
||||
|
||||
|
||||
class VixUiRangeInt:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"value": ("INT", {"default": 10}),
|
||||
"display_name": ("STRING", {"default": "Display Range"}),
|
||||
"optional": ("BOOLEAN", {"default": True}),
|
||||
"advanced": ("BOOLEAN", {"default": True}),
|
||||
"min": ("INT", {"default": 1}),
|
||||
"max": ("INT", {"default": 20}),
|
||||
"step": ("INT", {"default": 1}),
|
||||
"order": ("INT", {"default": 99}),
|
||||
"custom_id": ("STRING", {"default": ""}),
|
||||
},
|
||||
"optional": {
|
||||
"hidden": ("BOOLEAN", {"default": False}),
|
||||
},
|
||||
}
|
||||
|
||||
FUNCTION = "do_it"
|
||||
CATEGORY = "Visionatrix/UI"
|
||||
RETURN_TYPES = ("INT",)
|
||||
|
||||
@classmethod
|
||||
def do_it(cls, value, **kwargs) -> tuple:
|
||||
return (value,)
|
||||
|
||||
|
||||
class VixUiList:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"default_value": ("STRING", {}),
|
||||
"possible_values": ("STRING", {"default": "[]", "multiline": True}),
|
||||
"display_name": ("STRING", {"default": "Dropdown list"}),
|
||||
"optional": ("BOOLEAN", {"default": True}),
|
||||
"advanced": ("BOOLEAN", {"default": True}),
|
||||
"order": ("INT", {"default": 99}),
|
||||
"custom_id": ("STRING", {"default": ""}),
|
||||
},
|
||||
"optional": {
|
||||
"hidden": ("BOOLEAN", {"default": False}),
|
||||
},
|
||||
}
|
||||
|
||||
RETURN_TYPES = (any_typ,)
|
||||
FUNCTION = "do_it"
|
||||
CATEGORY = "Visionatrix/UI"
|
||||
|
||||
@classmethod
|
||||
def do_it(cls, default_value, **kwargs) -> tuple:
|
||||
possible_values = json.loads(kwargs["possible_values"])
|
||||
if isinstance(possible_values, dict) and default_value in possible_values:
|
||||
return (possible_values[default_value],)
|
||||
return (default_value,)
|
||||
|
||||
|
||||
class VixUiPrompt:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"text": (
|
||||
"STRING",
|
||||
{"default": "", "multiline": True, "dynamicPrompts": True},
|
||||
),
|
||||
"display_name": ("STRING", {"default": "Prompt"}),
|
||||
"optional": ("BOOLEAN", {"default": False}),
|
||||
"advanced": ("BOOLEAN", {"default": False}),
|
||||
"order": ("INT", {"default": 10}),
|
||||
"custom_id": ("STRING", {"default": ""}),
|
||||
},
|
||||
"optional": {
|
||||
"hidden": ("BOOLEAN", {"default": False}),
|
||||
"translatable": ("BOOLEAN", {"default": False}),
|
||||
},
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("STRING",)
|
||||
FUNCTION = "do_it"
|
||||
CATEGORY = "Visionatrix/UI"
|
||||
|
||||
@classmethod
|
||||
def do_it(cls, text, **kwargs) -> tuple:
|
||||
return (text,)
|
||||
|
||||
|
||||
class VixUiCheckboxLogic:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"state": ("BOOLEAN", {"default": False}),
|
||||
"display_name": ("STRING", {"default": "Display Name"}),
|
||||
"optional": ("BOOLEAN", {"default": True}),
|
||||
"advanced": ("BOOLEAN", {"default": True}),
|
||||
"order": ("INT", {"default": 99}),
|
||||
"custom_id": ("STRING", {"default": ""}),
|
||||
},
|
||||
"optional": {
|
||||
"input_off_state": (any_typ, {"lazy": True}),
|
||||
"input_on_state": (any_typ, {"lazy": True}),
|
||||
"hidden": ("BOOLEAN", {"default": False}),
|
||||
},
|
||||
}
|
||||
|
||||
RETURN_TYPES = (any_typ,)
|
||||
RETURN_NAMES = ("output_to",)
|
||||
CATEGORY = "Visionatrix/UI"
|
||||
FUNCTION = "do_it"
|
||||
|
||||
@classmethod
|
||||
def do_it(cls, state, **kwargs) -> tuple:
|
||||
if state is False:
|
||||
return (kwargs.get("input_off_state"),)
|
||||
return (kwargs.get("input_on_state"),)
|
||||
|
||||
@staticmethod
|
||||
def check_lazy_status(state, **kwargs):
|
||||
if state is False:
|
||||
return ["input_off_state"]
|
||||
return ["input_on_state"]
|
||||
|
||||
|
||||
class VixUiListLogic:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"default_value": ("STRING", {}),
|
||||
"possible_values": ("STRING", {"default": "[]", "multiline": True}),
|
||||
"display_name": ("STRING", {"default": "Display Name"}),
|
||||
"optional": ("BOOLEAN", {"default": True}),
|
||||
"advanced": ("BOOLEAN", {"default": True}),
|
||||
"order": ("INT", {"default": 99}),
|
||||
"custom_id": ("STRING", {"default": ""}),
|
||||
},
|
||||
"optional": {
|
||||
"input_first": (any_typ, {"lazy": True}),
|
||||
"input_second": (any_typ, {"lazy": True}),
|
||||
"input_third": (any_typ, {"lazy": True}),
|
||||
"input_fourth": (any_typ, {"lazy": True}),
|
||||
"input_fifth": (any_typ, {"lazy": True}),
|
||||
"input_sixth": (any_typ, {"lazy": True}),
|
||||
"hidden": ("BOOLEAN", {"default": False}),
|
||||
},
|
||||
}
|
||||
|
||||
RETURN_TYPES = (any_typ,)
|
||||
RETURN_NAMES = ("output_to",)
|
||||
CATEGORY = "Visionatrix/UI"
|
||||
FUNCTION = "do_it"
|
||||
|
||||
@classmethod
|
||||
def do_it(cls, default_value, **kwargs) -> tuple:
|
||||
list_with_values: list = json.loads(kwargs["possible_values"])
|
||||
index_to_return = list_with_values.index(default_value)
|
||||
if index_to_return == 0:
|
||||
return (kwargs["input_first"],)
|
||||
if index_to_return == 1:
|
||||
return (kwargs["input_second"],)
|
||||
if index_to_return == 2:
|
||||
return (kwargs["input_third"],)
|
||||
if index_to_return == 3:
|
||||
return (kwargs["input_fourth"],)
|
||||
if index_to_return == 4:
|
||||
return (kwargs["input_fifth"],)
|
||||
if index_to_return == 5:
|
||||
return (kwargs["input_sixth"],)
|
||||
raise RuntimeError("Workflow logic error")
|
||||
|
||||
@staticmethod
|
||||
def check_lazy_status(default_value, **kwargs):
|
||||
list_with_values: list = json.loads(kwargs["possible_values"])
|
||||
index_to_return = list_with_values.index(default_value)
|
||||
if index_to_return == 0:
|
||||
return ["input_first"]
|
||||
if index_to_return == 1:
|
||||
return ["input_second"]
|
||||
if index_to_return == 2:
|
||||
return ["input_third"]
|
||||
if index_to_return == 3:
|
||||
return ["input_fourth"]
|
||||
if index_to_return == 4:
|
||||
return ["input_fifth"]
|
||||
if index_to_return == 5:
|
||||
return ["input_sixth"]
|
||||
raise RuntimeError("Workflow logic error")
|
||||
|
||||
|
||||
class VixUiWorkflowMetadata:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"name": ("STRING", {}),
|
||||
"display_name": ("STRING", {}),
|
||||
"description": ("STRING", {"default": ""}),
|
||||
"author": ("STRING", {}),
|
||||
"homepage": ("STRING", {"default": ""}),
|
||||
"documentation": ("STRING", {"default": ""}),
|
||||
"license": ("STRING", {"default": ""}),
|
||||
"tags": ("STRING", {"default": '["general"]', "multiline": True}),
|
||||
"version": ("STRING", {"default": "1.0.0"}),
|
||||
},
|
||||
"optional": {
|
||||
"requires": ("STRING", {"default": "[]", "multiline": True}),
|
||||
"is_seed_supported": ("BOOLEAN", {"default": True}),
|
||||
"is_count_supported": ("BOOLEAN", {"default": True}),
|
||||
"is_translations_supported": ("BOOLEAN", {"default": False}),
|
||||
"is_macos_supported": ("BOOLEAN", {"default": True}),
|
||||
"required_memory_gb": (
|
||||
"FLOAT",
|
||||
{"default": 0.0, "step": 0.1, "round": False},
|
||||
),
|
||||
"hidden": ("BOOLEAN", {"default": False}),
|
||||
"remote_vae": ("BOOLEAN", {"default": False}),
|
||||
"long_description": ("STRING", {"default": "", "multiline": True}),
|
||||
},
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("STRING",)
|
||||
FUNCTION = "do_it"
|
||||
CATEGORY = "Visionatrix/UI"
|
||||
|
||||
@classmethod
|
||||
def do_it(cls, text, **kwargs) -> tuple:
|
||||
return (text,)
|
||||
|
||||
|
||||
class VixDynamicLoraDefinition:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"model": (
|
||||
"MODEL",
|
||||
{"tooltip": "The diffusion model the LoRA will be applied to."},
|
||||
),
|
||||
"clip": (
|
||||
"CLIP",
|
||||
{"tooltip": "The CLIP model the LoRA will be applied to."},
|
||||
),
|
||||
"base_model_type": (
|
||||
"STRING",
|
||||
{"tooltip": "The base type of model in CivitAI format."},
|
||||
),
|
||||
"description": (
|
||||
"STRING",
|
||||
{"tooltip": "Brief explanation of LoRA functionality at the added place."},
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("MODEL", "CLIP")
|
||||
OUTPUT_TOOLTIPS = ("The modified diffusion model.", "The modified CLIP model.")
|
||||
CATEGORY = "Visionatrix/UI"
|
||||
FUNCTION = "do_it"
|
||||
DESCRIPTION = "Node that allows dynamic selection of any supported LoRAs from CivitAI in the Visionatrix UI."
|
||||
|
||||
@classmethod
|
||||
def do_it(cls, model, clip, **kwargs) -> tuple:
|
||||
return model, clip
|
||||
|
||||
|
||||
class VixCheckboxLogic:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"state": ("BOOLEAN", {"default": False}),
|
||||
"input_off_state": (any_typ, {"lazy": True}),
|
||||
"input_on_state": (any_typ, {"lazy": True}),
|
||||
},
|
||||
"optional": {},
|
||||
}
|
||||
|
||||
RETURN_TYPES = (any_typ,)
|
||||
RETURN_NAMES = ("output_to",)
|
||||
CATEGORY = "Visionatrix/Logic"
|
||||
FUNCTION = "do_it"
|
||||
|
||||
@classmethod
|
||||
def do_it(cls, state, **kwargs) -> tuple:
|
||||
if state is False:
|
||||
return (kwargs.get("input_off_state"),)
|
||||
return (kwargs.get("input_on_state"),)
|
||||
|
||||
@staticmethod
|
||||
def check_lazy_status(state, **kwargs):
|
||||
if state is False:
|
||||
return ["input_off_state"]
|
||||
return ["input_on_state"]
|
||||
|
||||
|
||||
NODE_CLASS_MAPPINGS = {
|
||||
"VixUiAspectRatioSelector": VixUiAspectRatioSelector,
|
||||
"VixUiCheckbox": VixUiCheckbox,
|
||||
"VixUiRangeFloat": VixUiRangeFloat,
|
||||
"VixUiRangeScaleFloat": VixUiRangeScaleFloat,
|
||||
"VixUiRangeInt": VixUiRangeInt,
|
||||
"VixUiList": VixUiList,
|
||||
"VixUiPrompt": VixUiPrompt,
|
||||
"VixUiCheckboxLogic": VixUiCheckboxLogic,
|
||||
"VixUiListLogic": VixUiListLogic,
|
||||
"VixUiWorkflowMetadata": VixUiWorkflowMetadata,
|
||||
"VixDynamicLoraDefinition": VixDynamicLoraDefinition,
|
||||
"VixCheckboxLogic": VixCheckboxLogic,
|
||||
"StyleAlignedBatchAlign": StyleAlignedBatchAlign,
|
||||
"VixMultilineText": text.VixMultilineText,
|
||||
"VixTextConcatenate": text.VixTextConcatenate,
|
||||
"VixTextReplace": text.VixTextReplace,
|
||||
"VixDictionaryNew": text.VixDictionaryNew,
|
||||
"VixDictionaryConvert": text.VixDictionaryConvert,
|
||||
"VixDictionaryGet": text.VixDictionaryGet,
|
||||
"VixDictionaryUpdate": text.VixDictionaryUpdate,
|
||||
"VixImageFilters": image.VixImageFilters,
|
||||
}
|
||||
|
||||
NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"VixUiAspectRatioSelector": "Aspect Ratio (VixUI)",
|
||||
"VixUiCheckbox": "Checkbox (VixUI)",
|
||||
"VixUiRangeFloat": "Range Float (VixUI)",
|
||||
"VixUiRangeScaleFloat": "Range Scale Float (VixUI)",
|
||||
"VixUiRangeInt": "Range Int (VixUI)",
|
||||
"VixUiList": "List (VixUI)",
|
||||
"VixUiPrompt": "Prompt (VixUI)",
|
||||
"VixUiCheckboxLogic": "Checkbox Logic (VixUI)",
|
||||
"VixUiListLogic": "List Logic (VixUI)",
|
||||
"VixUiWorkflowMetadata": "Workflow Metadata (VixUI)",
|
||||
"VixDynamicLoraDefinition": "Vix Dynamic Lora Definition",
|
||||
"VixCheckboxLogic": "Vix Checkbox Logic",
|
||||
"StyleAlignedBatchAlign": "StyleAligned Batch Align",
|
||||
"VixMultilineText": "Text Multiline",
|
||||
"VixTextConcatenate": "Text Concatenate",
|
||||
"VixTextReplace": "Text Replace",
|
||||
"VixDictionaryNew": "Dictionary New",
|
||||
"VixDictionaryConvert": "Convert to Dictionary",
|
||||
"VixDictionaryGet": "Dictionary Get",
|
||||
"VixDictionaryUpdate": "Dictionary Update",
|
||||
"VixImageFilters": "Image Filters",
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
[project]
|
||||
name = "comfyui-visionatrix"
|
||||
version = "1.2.4"
|
||||
description = "The ComfyUI-Visionatrix nodes are designed for convenient ComfyUI to [a/Visionatrix](https://github.com/Visionatrix/Visionatrix) workflow support migration, in particular to extract prompt input params (input, textarea, checkbox, select, range, file) to be used in simplified Visionatrix UI."
|
||||
license = { file = "LICENSE" }
|
||||
requires-python = ">=3.10"
|
||||
classifiers = [
|
||||
"Programming Language :: Python :: 3 :: Only",
|
||||
"Programming Language :: Python :: 3.10",
|
||||
"Programming Language :: Python :: 3.11",
|
||||
"Programming Language :: Python :: 3.12",
|
||||
"Programming Language :: Python :: 3.13",
|
||||
]
|
||||
urls.Repository = "https://github.com/Visionatrix/ComfyUI-Visionatrix"
|
||||
|
||||
[tool.black]
|
||||
line-length = 120
|
||||
preview = true
|
||||
|
||||
[tool.ruff]
|
||||
target-version = "py310"
|
||||
line-length = 120
|
||||
lint.select = [
|
||||
"A",
|
||||
"B",
|
||||
"C",
|
||||
"E",
|
||||
"F",
|
||||
"G",
|
||||
"I",
|
||||
"PIE",
|
||||
"Q",
|
||||
"RET",
|
||||
"RUF",
|
||||
"S",
|
||||
"SIM",
|
||||
"UP",
|
||||
"W",
|
||||
]
|
||||
lint.extend-ignore = [
|
||||
"I001",
|
||||
"RUF100",
|
||||
"S311",
|
||||
"S603",
|
||||
]
|
||||
lint.mccabe.max-complexity = 20
|
||||
|
||||
[tool.isort]
|
||||
profile = "black"
|
||||
|
||||
[tool.comfy]
|
||||
PublisherId = "visionatrix"
|
||||
DisplayName = "ComfyUI-Visionatrix"
|
||||
Icon = "https://raw.githubusercontent.com/Visionatrix/VixFlowsDocs/main/screenshots/logo_org_400x400.png"
|
||||
@@ -0,0 +1,3 @@
|
||||
torch
|
||||
pillow
|
||||
numpy
|
||||
@@ -0,0 +1,155 @@
|
||||
# MIT License
|
||||
#
|
||||
# Copyright (c) 2023 Brian Fitzgerald
|
||||
# original repository: https://github.com/brianfitzgerald/style_aligned_comfy
|
||||
|
||||
import torch
|
||||
import torch.nn as nn
|
||||
from comfy.model_patcher import ModelPatcher
|
||||
|
||||
T = torch.Tensor
|
||||
|
||||
|
||||
class StyleAlignedArgs:
|
||||
def __init__(self, share_attn: str) -> None:
|
||||
self.adain_keys = "k" in share_attn
|
||||
self.adain_values = "v" in share_attn
|
||||
self.adain_queries = "q" in share_attn
|
||||
|
||||
share_attention: bool = True
|
||||
adain_queries: bool = True
|
||||
adain_keys: bool = True
|
||||
adain_values: bool = True
|
||||
|
||||
|
||||
def expand_first(
|
||||
feat: T,
|
||||
scale=1.0,
|
||||
) -> T:
|
||||
b = feat.shape[0]
|
||||
feat_style = torch.stack((feat[0], feat[b // 2])).unsqueeze(1)
|
||||
if scale == 1:
|
||||
feat_style = feat_style.expand(2, b // 2, *feat.shape[1:])
|
||||
else:
|
||||
feat_style = feat_style.repeat(1, b // 2, 1, 1, 1)
|
||||
feat_style = torch.cat([feat_style[:, :1], scale * feat_style[:, 1:]], dim=1)
|
||||
return feat_style.reshape(*feat.shape)
|
||||
|
||||
|
||||
def concat_first(feat: T, dim=2, scale=1.0) -> T:
|
||||
feat_style = expand_first(feat, scale=scale)
|
||||
return torch.cat((feat, feat_style), dim=dim)
|
||||
|
||||
|
||||
def calc_mean_std(feat, eps: float = 1e-5) -> "tuple[T, T]":
|
||||
feat_std = (feat.var(dim=-2, keepdims=True) + eps).sqrt()
|
||||
feat_mean = feat.mean(dim=-2, keepdims=True)
|
||||
return feat_mean, feat_std
|
||||
|
||||
|
||||
def adain(feat: T) -> T:
|
||||
feat_mean, feat_std = calc_mean_std(feat)
|
||||
feat_style_mean = expand_first(feat_mean)
|
||||
feat_style_std = expand_first(feat_std)
|
||||
feat = (feat - feat_mean) / feat_std
|
||||
return feat * feat_style_std + feat_style_mean
|
||||
|
||||
|
||||
class SharedAttentionProcessor:
|
||||
def __init__(self, args: StyleAlignedArgs, scale: float):
|
||||
self.args = args
|
||||
self.scale = scale
|
||||
|
||||
def __call__(self, q, k, v, extra_options):
|
||||
if self.args.adain_queries:
|
||||
q = adain(q)
|
||||
if self.args.adain_keys:
|
||||
k = adain(k)
|
||||
if self.args.adain_values:
|
||||
v = adain(v)
|
||||
if self.args.share_attention:
|
||||
k = concat_first(k, -2, scale=self.scale)
|
||||
v = concat_first(v, -2)
|
||||
|
||||
return q, k, v
|
||||
|
||||
|
||||
def get_norm_layers(
|
||||
layer: nn.Module,
|
||||
norm_layers_: "dict[str, list[nn.GroupNorm | nn.LayerNorm]]",
|
||||
share_layer_norm: bool,
|
||||
share_group_norm: bool,
|
||||
):
|
||||
if isinstance(layer, nn.LayerNorm) and share_layer_norm:
|
||||
norm_layers_["layer"].append(layer)
|
||||
if isinstance(layer, nn.GroupNorm) and share_group_norm:
|
||||
norm_layers_["group"].append(layer)
|
||||
else:
|
||||
for child_layer in layer.children():
|
||||
get_norm_layers(child_layer, norm_layers_, share_layer_norm, share_group_norm)
|
||||
|
||||
|
||||
def register_norm_forward(
|
||||
norm_layer: nn.GroupNorm | nn.LayerNorm,
|
||||
) -> nn.GroupNorm | nn.LayerNorm:
|
||||
if not hasattr(norm_layer, "orig_forward"):
|
||||
setattr(norm_layer, "orig_forward", norm_layer.forward) # noqa
|
||||
orig_forward = norm_layer.orig_forward
|
||||
|
||||
def forward_(hidden_states: T) -> T:
|
||||
n = hidden_states.shape[-2]
|
||||
hidden_states = concat_first(hidden_states, dim=-2)
|
||||
hidden_states = orig_forward(hidden_states) # type: ignore
|
||||
return hidden_states[..., :n, :]
|
||||
|
||||
norm_layer.forward = forward_ # type: ignore
|
||||
return norm_layer
|
||||
|
||||
|
||||
def register_shared_norm(
|
||||
model: ModelPatcher,
|
||||
share_group_norm: bool = True,
|
||||
share_layer_norm: bool = True,
|
||||
):
|
||||
norm_layers = {"group": [], "layer": []}
|
||||
get_norm_layers(model.model, norm_layers, share_layer_norm, share_group_norm)
|
||||
print(f"Patching {len(norm_layers['group'])} group norms, {len(norm_layers['layer'])} layer norms.")
|
||||
return [register_norm_forward(layer) for layer in norm_layers["group"]] + [
|
||||
register_norm_forward(layer) for layer in norm_layers["layer"]
|
||||
]
|
||||
|
||||
|
||||
SHARE_NORM_OPTIONS = ["both", "group", "layer", "disabled"]
|
||||
SHARE_ATTN_OPTIONS = ["q+k", "q+k+v", "disabled"]
|
||||
|
||||
|
||||
class StyleAlignedBatchAlign:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"model": ("MODEL",),
|
||||
"share_norm": (SHARE_NORM_OPTIONS,),
|
||||
"share_attn": (SHARE_ATTN_OPTIONS,),
|
||||
"scale": ("FLOAT", {"default": 1, "min": 0, "max": 1.0, "step": 0.1}),
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("MODEL",)
|
||||
FUNCTION = "patch"
|
||||
CATEGORY = "style_aligned"
|
||||
|
||||
def patch(
|
||||
self,
|
||||
model: ModelPatcher,
|
||||
share_norm: str,
|
||||
share_attn: str,
|
||||
scale: float,
|
||||
):
|
||||
m = model.clone()
|
||||
share_group_norm = share_norm in ["group", "both"]
|
||||
share_layer_norm = share_norm in ["layer", "both"]
|
||||
register_shared_norm(model, share_group_norm, share_layer_norm)
|
||||
args = StyleAlignedArgs(share_attn)
|
||||
m.set_model_attn1_patch(SharedAttentionProcessor(args, scale))
|
||||
return (m,)
|
||||
@@ -0,0 +1,218 @@
|
||||
import ast
|
||||
import re
|
||||
|
||||
|
||||
class VixMultilineText:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"text": (
|
||||
"STRING",
|
||||
{"default": "", "multiline": True, "dynamicPrompts": False},
|
||||
),
|
||||
},
|
||||
"optional": {},
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("STRING",)
|
||||
FUNCTION = "do_it"
|
||||
CATEGORY = "Visionatrix/Text"
|
||||
DEPRECATED = True
|
||||
|
||||
@classmethod
|
||||
def do_it(cls, text, **kwargs) -> tuple:
|
||||
return (text,)
|
||||
|
||||
|
||||
class VixTextConcatenate:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"delimiter": ("STRING", {"default": ", "}),
|
||||
"clean_whitespace": (["true", "false"],),
|
||||
},
|
||||
"optional": {
|
||||
"text_a": ("STRING", {"forceInput": True}),
|
||||
"text_b": ("STRING", {"forceInput": True}),
|
||||
"text_c": ("STRING", {"forceInput": True}),
|
||||
"text_d": ("STRING", {"forceInput": True}),
|
||||
},
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("STRING",)
|
||||
FUNCTION = "do_it"
|
||||
CATEGORY = "Visionatrix/Text"
|
||||
DEPRECATED = True
|
||||
|
||||
@classmethod
|
||||
def do_it(cls, delimiter: str, clean_whitespace: str, **kwargs):
|
||||
delim = "\n" if delimiter == "\\n" else delimiter
|
||||
strip = clean_whitespace.lower() == "true"
|
||||
parts = ((val.strip() if strip else val) for _, val in sorted(kwargs.items()) if isinstance(val, str))
|
||||
return (delim.join(filter(None, parts)),)
|
||||
|
||||
|
||||
class VixTextReplace:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"text": ("STRING", {"forceInput": True}),
|
||||
"find": ("STRING", {"default": "", "multiline": False}),
|
||||
"replace": ("STRING", {"default": "", "multiline": False}),
|
||||
},
|
||||
"optional": {},
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("STRING", "NUMBER", "FLOAT", "INT")
|
||||
RETURN_NAMES = (
|
||||
"result_text",
|
||||
"replacement_count_number",
|
||||
"replacement_count_float",
|
||||
"replacement_count_int",
|
||||
)
|
||||
FUNCTION = "do_it"
|
||||
CATEGORY = "Visionatrix/Text"
|
||||
DEPRECATED = True
|
||||
|
||||
@classmethod
|
||||
def do_it(cls, text: str, find: str, replace: str):
|
||||
modified_text, count = re.subn(find, replace, text)
|
||||
return modified_text, count, float(count), count
|
||||
|
||||
|
||||
class VixDictionaryNew:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"key_1": ("STRING", {"default": "", "multiline": False}),
|
||||
"value_1": ("STRING", {"default": "", "multiline": False}),
|
||||
},
|
||||
"optional": {
|
||||
"key_2": ("STRING", {"default": "", "multiline": False}),
|
||||
"value_2": ("STRING", {"default": "", "multiline": False}),
|
||||
"key_3": ("STRING", {"default": "", "multiline": False}),
|
||||
"value_3": ("STRING", {"default": "", "multiline": False}),
|
||||
"key_4": ("STRING", {"default": "", "multiline": False}),
|
||||
"value_4": ("STRING", {"default": "", "multiline": False}),
|
||||
"key_5": ("STRING", {"default": "", "multiline": False}),
|
||||
"value_5": ("STRING", {"default": "", "multiline": False}),
|
||||
"key_6": ("STRING", {"default": "", "multiline": False}),
|
||||
"value_6": ("STRING", {"default": "", "multiline": False}),
|
||||
"key_7": ("STRING", {"default": "", "multiline": False}),
|
||||
"value_7": ("STRING", {"default": "", "multiline": False}),
|
||||
"key_8": ("STRING", {"default": "", "multiline": False}),
|
||||
"value_8": ("STRING", {"default": "", "multiline": False}),
|
||||
"key_9": ("STRING", {"default": "", "multiline": False}),
|
||||
"value_9": ("STRING", {"default": "", "multiline": False}),
|
||||
},
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("DICT",)
|
||||
FUNCTION = "do_it"
|
||||
CATEGORY = "Visionatrix/Text"
|
||||
|
||||
@classmethod
|
||||
def do_it(
|
||||
cls,
|
||||
key_1: str,
|
||||
value_1: str,
|
||||
key_2: str,
|
||||
value_2: str,
|
||||
key_3: str,
|
||||
value_3: str,
|
||||
key_4: str,
|
||||
value_4: str,
|
||||
key_5: str,
|
||||
value_5: str,
|
||||
key_6: str,
|
||||
value_6: str,
|
||||
key_7: str,
|
||||
value_7: str,
|
||||
key_8: str,
|
||||
value_8: str,
|
||||
key_9: str,
|
||||
value_9: str,
|
||||
):
|
||||
return (
|
||||
{
|
||||
k: v
|
||||
for k, v in [
|
||||
(key_1, value_1),
|
||||
(key_2, value_2),
|
||||
(key_3, value_3),
|
||||
(key_4, value_4),
|
||||
(key_5, value_5),
|
||||
(key_6, value_6),
|
||||
(key_7, value_7),
|
||||
(key_8, value_8),
|
||||
(key_9, value_9),
|
||||
]
|
||||
if k
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
class VixDictionaryConvert:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {"dictionary_text": ("STRING", {"forceInput": True})},
|
||||
"optional": {},
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("DICT",)
|
||||
FUNCTION = "do_it"
|
||||
CATEGORY = "Visionatrix/Text"
|
||||
|
||||
@classmethod
|
||||
def do_it(cls, dictionary_text: str):
|
||||
return (ast.literal_eval(dictionary_text),)
|
||||
|
||||
|
||||
class VixDictionaryGet:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"dictionary": ("DICT",),
|
||||
"key": ("STRING", {"default": "", "multiline": False}),
|
||||
},
|
||||
"optional": {
|
||||
"default_value": ("STRING", {"default": "", "multiline": False}),
|
||||
},
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("STRING",)
|
||||
FUNCTION = "do_it"
|
||||
CATEGORY = "Visionatrix/Text"
|
||||
|
||||
@classmethod
|
||||
def do_it(cls, dictionary: dict, key: str, default_value=""):
|
||||
return (str(dictionary.get(key, default_value)),)
|
||||
|
||||
|
||||
class VixDictionaryUpdate:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"dict_1": ("DICT",),
|
||||
"dict_2": ("DICT",),
|
||||
},
|
||||
"optional": {
|
||||
"dict_3": ("DICT",),
|
||||
"dict_4": ("DICT",),
|
||||
},
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("DICT",)
|
||||
FUNCTION = "do_it"
|
||||
CATEGORY = "Visionatrix/Text"
|
||||
|
||||
@classmethod
|
||||
def do_it(cls, dict_1: dict, dict_2: dict, dict_3: dict | None = None, dict_4: dict | None = None):
|
||||
return ({**dict_1, **dict_2, **(dict_3 or {}), **(dict_4 or {})},)
|
||||
@@ -0,0 +1,18 @@
|
||||
import numpy as np
|
||||
from PIL import Image
|
||||
from torch import Tensor, from_numpy
|
||||
|
||||
|
||||
def image_to_pillow(image: Tensor) -> Image.Image:
|
||||
return Image.fromarray(np.clip(255.0 * image.cpu().numpy().squeeze(), 0, 255).astype(np.uint8))
|
||||
|
||||
|
||||
def images_to_pillow(images: Tensor | list[Tensor]) -> list[Image.Image]:
|
||||
pillow_images = []
|
||||
for _bn, image in enumerate(images):
|
||||
pillow_images.append(image_to_pillow(image))
|
||||
return pillow_images
|
||||
|
||||
|
||||
def pillow_to_image(image: Image.Image) -> Tensor:
|
||||
return from_numpy(np.array(image).astype(np.float32) / 255.0).unsqueeze(0)
|
||||
Reference in New Issue
Block a user