From 7bc2dad81ddda8cdcbdcae2996e0c67d6fb44eff Mon Sep 17 00:00:00 2001 From: sn0w12 Date: Thu, 22 Feb 2024 00:51:21 +0100 Subject: [PATCH] Added custom characters, fixed typo --- .gitignore | 1 + README.md | 4 ++-- characters.json | 12 ++++++------ src/character_select.py | 28 ++++++++++++++++++++++------ 4 files changed, 31 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index dc5cd64..560fce6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ __pycache__ *.pyc +custom_characters.json diff --git a/README.md b/README.md index f4e6561..76dfdd2 100644 --- a/README.md +++ b/README.md @@ -67,8 +67,8 @@ Many of the nodes require these paths to be in your extra_model_paths.yaml (with >
> ℹ️ See More Information > -> - Loads characters.json and outputs prompt based on it. -> - Note: Currently very small list, feel free to add your own to the json file. +> - Loads `characters.json` and outputs prompt based on it. +> - You can create a file named `custom_characters.json` and add characters there if you want, they will be loaded with all the other characters if you format it like the `characters.json` file. > > ![Character Selector](./imgs/character_selector.png) >
diff --git a/characters.json b/characters.json index a6cceda..736b023 100644 --- a/characters.json +++ b/characters.json @@ -2,32 +2,32 @@ { "name": "Darkness (Konosuba)", "associated_string": "darkness \\(konosuba\\), kono subarashii sekai ni shukufuku wo!", - "prompt": "blonde hair, blue eyes, x hair ornament, large breasts, hair between eyes, hair ornament, long hair, " + "prompt": "blonde hair, blue eyes, x hair ornament, large breasts, hair between eyes, hair ornament, long hair" }, { "name": "Ghislaine Dedoldia (Mushoku Tensei)", "associated_string": "ghislaine dedoldia, mushoku tensei", - "prompt": "animal ear fluff, animal ears, eyepatch, grey hair, large breasts, long hair, red eyes, dark-skinned female, dark skin, " + "prompt": "animal ear fluff, animal ears, eyepatch, grey hair, large breasts, long hair, red eyes, dark-skinned female, dark skin" }, { "name": "Uzaki Hana (Uzaki-chan)", "associated_string": "uzaki hana, uzaki-chan wa asobitai!", - "prompt": "fang, grey hair, looking at viewer, short hair, blue eyes, breasts, large breasts, " + "prompt": "fang, grey hair, looking at viewer, short hair, blue eyes, breasts, large breasts" }, { "name": "Gotoh Hitori (Bocchi the Rock!)", "associated_string": "gotoh hitori, bocchi the rock!", - "prompt": "pink hair, blue eyes, breasts, cube hair ornament, hair between eyes, hair ornament, large breasts, long hair, " + "prompt": "pink hair, blue eyes, breasts, cube hair ornament, hair between eyes, hair ornament, large breasts, long hair" }, { "name": "Aqua (Konosuba)", "associated_string": "aqua \\(konosuba\\), kono subarashii sekai ni shukufuku wo!", - "prompt": "blue eyes, blue hair, hair ornament, long hair, large breasts, " + "prompt": "blue eyes, blue hair, hair ornament, long hair, large breasts" }, { "name": "Nami (One Piece)", "associated_string": "nami \\(one piece\\), one piece", - "prompt": "orange hair, orange eyes, large breasts, shoulder tattoo, long hair, " + "prompt": "orange hair, orange eyes, large breasts, shoulder tattoo, long hair" }, { "name": "Power (Chainsaw Man)", diff --git a/src/character_select.py b/src/character_select.py index dcca49b..e6286f0 100644 --- a/src/character_select.py +++ b/src/character_select.py @@ -7,11 +7,24 @@ class CharacterSelectNode: # Check if the last part of the path is 'src' and adjust the path accordingly if os.path.basename(dir_path) == "src": dir_path = os.path.dirname(dir_path) + # Construct the path to the 'characters.json' file json_path = os.path.join(dir_path, 'characters.json') # Load character data from the JSON file with open(json_path, 'r') as file: character_data = json.load(file) + + # Attempt to load 'custom_characters.json' and merge its contents + custom_json_path = os.path.join(dir_path, 'custom_characters.json') + if os.path.exists(custom_json_path): + with open(custom_json_path, 'r') as file: + custom_character_data = json.load(file) + if custom_character_data: # Check if the custom data is not empty + # Merge custom character data, prioritizing existing data in character_data + for custom_character in custom_character_data: + if custom_character['name'] not in [character['name'] for character in character_data]: + character_data.append(custom_character) + # Create a dictionary mapping character names to their data character_dict = {character['name']: character for character in character_data} @@ -22,7 +35,7 @@ class CharacterSelectNode: "required": { "character": (character_names, ), "character_strength": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 100.0, "step": 0.05, "round": 0.01}), - "character_pronpt": ("BOOLEAN", {"default": False}), + "character_prompt": ("BOOLEAN", {"default": False}), "xl": ("BOOLEAN", {"default": False},), }, } @@ -32,16 +45,19 @@ class CharacterSelectNode: FUNCTION = "find_associated_string" CATEGORY = "sn0w" - def find_associated_string(self, character, character_strength, character_pronpt, xl): + def find_associated_string(self, character, character_strength, character_prompt, xl): char_item = self.character_dict.get(character) if char_item: associated_string = char_item['associated_string'] - prompt = char_item['prompt'] if character_pronpt else "" + prompt = char_item['prompt'] if character_prompt else "" strength_part = f":{character_strength}" if character_strength != 1 else None - if strength_part: - return (f"({associated_string}{strength_part}), ", prompt, xl,) + if associated_string != "": + if strength_part: + return (f"({associated_string}{strength_part}), ", prompt, xl,) + else: + return (f"{associated_string}, ", prompt, xl,) else: - return (f"{associated_string}, ", prompt, xl,) + return ("", prompt, xl,) return ("None", "None", "None")