diff --git a/README.md b/README.md index 7db3011..8cc3117 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# πŸ”— Comfyui : Bjornulf_custom_nodes v0.8 πŸ”— +# πŸ”— Comfyui : Bjornulf_custom_nodes v0.9 πŸ”— # Dependencies @@ -17,6 +17,7 @@ - **v0.8**: Combine images : add an option to put image top, bottom or center. - **v0.8**: Combine texts : add option for slashes / - **v0.8**: Add basic node to transform greenscreen in to transparency. +- **v0.9**: Add a new node : Return one random line from input. # πŸ“ Nodes descriptions @@ -178,4 +179,11 @@ Update 0.8 : Also have a option to put image top, bottom or center. **Description:** Transform greenscreen into transparency. -Need clean greenscreen ofc. (Can adjust threshold but very basic node.) \ No newline at end of file +Need clean greenscreen ofc. (Can adjust threshold but very basic node.) + +## 26 - 🎲 Random line from input +![Combine Images](screenshots/random_line_from_input.png) + +**Description:** +Take a random line from an input text. (When using multiple "Write Text" nodes is annoying for example, you can use that and just copy/paste a list from outside.) + diff --git a/__init__.py b/__init__.py index 584faa2..62a5d9b 100644 --- a/__init__.py +++ b/__init__.py @@ -30,6 +30,7 @@ from .image_to_grayscale import GrayscaleTransform from .combine_background_overlay import CombineBackgroundOverlay from .save_bjornulf_lobechat import SaveBjornulfLobeChat from .green_to_transparency import GreenScreenToTransparency +from .random_line_from_input import RandomLineFromInput # from .check_black_image import CheckBlackImage # from .clear_vram import ClearVRAM @@ -39,6 +40,7 @@ NODE_CLASS_MAPPINGS = { # "Bjornulf_CustomStringType": CustomStringType, "Bjornulf_ollamaLoader": ollamaLoader, "Bjornulf_GreenScreenToTransparency": GreenScreenToTransparency, + "Bjornulf_RandomLineFromInput": RandomLineFromInput, # "Bjornulf_CheckBlackImage": CheckBlackImage, # "Bjornulf_ClearVRAM": ClearVRAM, "Bjornulf_SaveBjornulfLobeChat": SaveBjornulfLobeChat, @@ -80,6 +82,7 @@ NODE_DISPLAY_NAME_MAPPINGS = { # "Bjornulf_CheckBlackImage": "πŸ”² Check Black Image (Empty mask)", "Bjornulf_SaveBjornulfLobeChat": "πŸ–ΌπŸ’¬ Save image for Bjornulf LobeChat", # "Bjornulf_ClearVRAM": "🧹 Clear VRAM", + "Bjornulf_RandomLineFromInput": "🎲 Random line from input", "Bjornulf_ShowText": "πŸ‘ Show (Text)", "Bjornulf_ShowInt": "πŸ‘ Show (Int)", "Bjornulf_ShowFloat": "πŸ‘ Show (Float)", @@ -89,7 +92,7 @@ NODE_DISPLAY_NAME_MAPPINGS = { # "πŸ”²βžœβ¬› Transparency to color", "Bjornulf_ResizeImage": "πŸ“ Resize Image", "Bjornulf_SaveImagePath": "πŸ–Ό Save Image (exact path, exact name) βš οΈπŸ’£", - "Bjornulf_SaveImageToFolder": "πŸ–ΌπŸ“ Save Image to a folder", + "Bjornulf_SaveImageToFolder": "πŸ–ΌπŸ“ Save Image(s) to a folder", "Bjornulf_SaveTmpImage": "πŸ–Ό Save Image (tmp_api.png) βš οΈπŸ’£", # "Bjornulf_SaveApiImage": "πŸ–Ό Save Image (./output/api_00001.png...)", "Bjornulf_SaveText": "πŸ’Ύ Save Text", #Make SaveCharacter, SaveLocation, SaveCamera, SaveAction, SaveClothes, SaveEmotion... diff --git a/random_line_from_input.py b/random_line_from_input.py new file mode 100644 index 0000000..46710dd --- /dev/null +++ b/random_line_from_input.py @@ -0,0 +1,34 @@ +import random + +class RandomLineFromInput: + @classmethod + def INPUT_TYPES(cls): + return { + "required": { + "text": ("STRING", {"forceInput": True}), + "seed": ("INT", {"default": 1}), + }, + } + + RETURN_TYPES = ("STRING",) + FUNCTION = "random_line" + OUTPUT_IS_LIST = (False,) + CATEGORY = "Bjornulf" + + def random_line(self, text, seed): + random.seed(seed) + + # Split the input text into lines + lines = text.split('\n') + + # Remove empty lines and strip whitespace + lines = [line.strip() for line in lines if line.strip()] + + if not lines: + return ([""],) + + # Select a random line + chosen_line = random.choice(lines) + + # Return as a list with one element + return ([chosen_line],) \ No newline at end of file diff --git a/save_bjornulf_lobechat.py b/save_bjornulf_lobechat.py index 7916e11..496fe62 100644 --- a/save_bjornulf_lobechat.py +++ b/save_bjornulf_lobechat.py @@ -41,9 +41,6 @@ class SaveBjornulfLobeChat: break counter += 1 - # Save the image with the determined filename - img.save(filename, format="PNG") - # Prepare metadata metadata = PngInfo() if prompt is not None: @@ -57,6 +54,9 @@ class SaveBjornulfLobeChat: if os.path.exists(link_path): os.remove(link_path) os.symlink(os.path.abspath(filename), link_path) + + # Save the image with the determined filename + img.save(os.path.abspath(filename), format="PNG", pnginfo=metadata) print(f"Image saved as: {filename}") diff --git a/save_img_to_folder.py b/save_img_to_folder.py index 098f6fc..18662ef 100644 --- a/save_img_to_folder.py +++ b/save_img_to_folder.py @@ -47,4 +47,4 @@ class SaveImageToFolder: print(f"Image saved as: {filename}") results.append({"filename": filename}) - return {"ui": {"images": results}} \ No newline at end of file + return {"ui": {"images": [{"filename": filename, "type": "output"}]}} \ No newline at end of file diff --git a/screenshots/random_line_from_input.png b/screenshots/random_line_from_input.png new file mode 100644 index 0000000..4cad91b Binary files /dev/null and b/screenshots/random_line_from_input.png differ diff --git a/web/js/random_line_from_input.js b/web/js/random_line_from_input.js new file mode 100644 index 0000000..5d40009 --- /dev/null +++ b/web/js/random_line_from_input.js @@ -0,0 +1,14 @@ +import { app } from "../../../scripts/app.js"; + +app.registerExtension({ + name: "Bjornulf.RandomLineFromInput", + async nodeCreated(node) { + if (node.comfyClass === "Bjornulf_RandomLineFromInput") { + // Set seed widget to hidden input + const seedWidget = node.widgets.find(w => w.name === "seed"); + if (seedWidget) { + seedWidget.type = "HIDDEN"; + } + } + } +});