Added custom characters, fixed typo

This commit is contained in:
sn0w12
2024-02-22 00:51:21 +01:00
parent 0f6c60da18
commit 7bc2dad81d
4 changed files with 31 additions and 14 deletions
+1
View File
@@ -1,3 +1,4 @@
__pycache__
*.pyc
custom_characters.json
+2 -2
View File
@@ -67,8 +67,8 @@ Many of the nodes require these paths to be in your extra_model_paths.yaml (with
> <details>
> <summary>ℹ️ <i>See More Information</i></summary>
>
> - 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)
> </details>
+6 -6
View File
@@ -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)",
+22 -6
View File
@@ -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")