diff --git a/README.md b/README.md index 99f1371..ea2d73a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# πŸ”— Comfyui : Bjornulf_custom_nodes v0.37 πŸ”— +# πŸ”— Comfyui : Bjornulf_custom_nodes v0.38 πŸ”— # ❀️ Coffee : β˜•β˜•β˜•β˜•β˜• 5/5 @@ -85,6 +85,7 @@ wget --content-disposition -P /workspace/ComfyUI/models/checkpoints "https://civ - **v0.35**: Great improvements of the TTS node 31. It will also save the audio file in the "ComfyUI/Bjornulf_TTS/" folder. - Not tested on windows yet - - **v0.36**: Fix random model. - **v0.37**: New node : Random Load checkpoint (Model Selector). Alternative to the random checkpoint node. (Not preloading all checkpoints in memory, slower to switch between checkpoints, but more outputs to decide where to store your results.) +- **v0.38**: New node : If-Else logic. (input == compare_with), examples with different latent space size. +fix some deserialization issues. # πŸ“ Nodes descriptions @@ -526,4 +527,31 @@ Select an image from a list of images. Useful in combination with my Load images from folder and preview image nodes. You can also of course make a group node, like this one, which is the same as the screenshot above : -![pick input](screenshots/select_image_group.png) \ No newline at end of file +![pick input](screenshots/select_image_group.png) + +### 45 - πŸ”€ If-Else (input == compare_with) + +![if else](screenshots/if1.png) + +**Description:** +If the `input` given is equal to the `compare_with` given in the widget, it will forward `send_if_true`, otherwise it will forward `send_if_false`. +You can forward anything, below is an example of forwarding a different size of latent space depending if it's SDXL or not. + +![if else](screenshots/if2.png) + +If-Else are chainables, just connect `output` to `send_if_false`. +⚠️ Always simply test `input` with `compare_with`, and connect the desired value to `send_if_true`. ⚠️ +Here a simple example with 2 If-Else nodes (choose between 3 different resolutions). ❗ Notice the same write text node is connected to both If-Else nodes input : + +![if else](screenshots/if3.png) + +Let's take a similar example but let's use my Write loop text node to display all 3 types once : + +![if else](screenshots/if4.png) + +If you understood the previous examples, here is a complete example that will create 3 images, landscape, portrait and normal : + +![if else](screenshots/if5.png) + +Workflow is hidden for simplicity, but is very basic, just connect latent to Ksampler, nothing special.) +You can also connect the same advanced loop write text node with my save folder node to save the images (landscape/portrait/normal) in separate folders, but you do you... \ No newline at end of file diff --git a/__init__.py b/__init__.py index 4a23f11..a0ea008 100644 --- a/__init__.py +++ b/__init__.py @@ -49,6 +49,7 @@ from .loop_write_text import LoopWriteText from .load_images_from_folder import LoadImagesFromSelectedFolder from .select_image_from_list import SelectImageFromList from .random_model_selector import RandomModelSelector +from .if_else import IfElse # from .pass_preview_image import PassPreviewImage # from .check_black_image import CheckBlackImage @@ -58,6 +59,7 @@ from .random_model_selector import RandomModelSelector NODE_CLASS_MAPPINGS = { # "Bjornulf_CustomStringType": CustomStringType, "Bjornulf_ollamaLoader": ollamaLoader, + "Bjornulf_IfElse": IfElse, "Bjornulf_RandomModelSelector": RandomModelSelector, "Bjornulf_SelectImageFromList": SelectImageFromList, "Bjornulf_WriteText": WriteText, @@ -167,6 +169,7 @@ NODE_DISPLAY_NAME_MAPPINGS = { "Bjornulf_PauseResume": "⏸️ Paused. Resume or Stop, Pick πŸ‘‡", "Bjornulf_LoadImagesFromSelectedFolder": "πŸ“‚πŸ–Ό Load Images from output folder", "Bjornulf_SelectImageFromList": "πŸ–ΌπŸ” Select an Image, Pick", + "Bjornulf_IfElse": "πŸ”€ If-Else (input == compare_with)", } WEB_DIRECTORY = "./web" diff --git a/if_else.py b/if_else.py new file mode 100644 index 0000000..6888407 --- /dev/null +++ b/if_else.py @@ -0,0 +1,26 @@ +class Everything(str): + def __ne__(self, __value: object) -> bool: + return False + +class IfElse: + @classmethod + def INPUT_TYPES(cls): + return { + "required": { + "input": ("STRING", {"forceInput": True, "multiline": False}), + "send_if_true": (Everything("*"),), + "send_if_false": (Everything("*"),), + "compare_with": ("STRING", {"multiline": False}), + }, + } + + RETURN_TYPES = (Everything("*"),"STRING") + RETURN_NAMES = ("output","true_or_false") + FUNCTION = "if_else" + CATEGORY = "Bjornulf" + + def if_else(self, input, send_if_true, send_if_false, compare_with): + if input == compare_with: + return (send_if_true,"True") + else: + return (send_if_false,"False") \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 29997ab..8eda4b4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "bjornulf_custom_nodes" description = "Nodes: Ollama, Text to Speech, Combine Texts, Random Texts, Save image for Bjornulf LobeChat, Text with random Seed, Random line from input, Combine images, Image to grayscale (black & white), Remove image Transparency (alpha), Resize Image, ..." -version = "0.37" +version = "0.38" license = {file = "LICENSE"} [project.urls] diff --git a/screenshots/if1.png b/screenshots/if1.png new file mode 100644 index 0000000..62fd179 Binary files /dev/null and b/screenshots/if1.png differ diff --git a/screenshots/if2.png b/screenshots/if2.png new file mode 100644 index 0000000..f50892f Binary files /dev/null and b/screenshots/if2.png differ diff --git a/screenshots/if3.png b/screenshots/if3.png new file mode 100644 index 0000000..6e80e45 Binary files /dev/null and b/screenshots/if3.png differ diff --git a/screenshots/if4.png b/screenshots/if4.png new file mode 100644 index 0000000..fc165e2 Binary files /dev/null and b/screenshots/if4.png differ diff --git a/screenshots/if5.png b/screenshots/if5.png new file mode 100644 index 0000000..dd5c83a Binary files /dev/null and b/screenshots/if5.png differ diff --git a/web/js/random_model_selector.js b/web/js/random_model_selector.js index f600964..8b8dacc 100644 --- a/web/js/random_model_selector.js +++ b/web/js/random_model_selector.js @@ -49,12 +49,48 @@ app.registerExtension({ }; } - // Set seed widget to hidden input + // Set seed widget to integer input const seedWidget = node.widgets.find((w) => w.name === "seed"); if (seedWidget) { - seedWidget.type = "HIDDEN"; + seedWidget.type = "HIDDEN"; // Hide seed widget after restoring saved state } + // Handle deserialization + const originalOnConfigure = node.onConfigure; + node.onConfigure = function(info) { + if (originalOnConfigure) { + originalOnConfigure.call(this, info); + } + + // Restore model widgets based on saved properties + const savedProperties = info.properties; + if (savedProperties) { + Object.keys(savedProperties).forEach(key => { + if (key.startsWith("model_")) { + const widgetName = key; + const widgetValue = savedProperties[key]; + const existingWidget = node.widgets.find(w => w.name === widgetName); + if (existingWidget) { + existingWidget.value = widgetValue; + } else { + node.addWidget("combo", widgetName, widgetValue, () => {}, { + values: node.widgets.find(w => w.name === "model_1").options.values + }); + } + } + }); + } + + // Ensure seed is a valid integer + const seedWidget = node.widgets.find(w => w.name === "seed"); + if (seedWidget && isNaN(parseInt(seedWidget.value))) { + seedWidget.value = 0; // Set a default value if invalid + } + + // Update model inputs after restoring saved state + updateModelInputs(); + }; + // Initial update updateModelInputs(); }