Update sdxl_prompt_styler.py
Added all styles merged file loading Added encoding and error ignoring to avoid encoding errors at load
This commit is contained in:
+53
-2
@@ -4,7 +4,7 @@ import os
|
||||
def read_json_file(file_path):
|
||||
try:
|
||||
# Open file, load JSON content into python dictionary, and return it.
|
||||
with open(file_path, 'r') as file:
|
||||
with open(file_path, 'r', encoding="cp437", errors='ignore') as file:
|
||||
json_data = json.load(file)
|
||||
return json_data
|
||||
except Exception as e:
|
||||
@@ -108,6 +108,55 @@ class SDXLPromptStylerMisc:
|
||||
|
||||
return positive_prompt, negative_prompt
|
||||
|
||||
class SDXLPromptStylerAll:
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def INPUT_TYPES(self):
|
||||
# Get current file's directory
|
||||
p = os.path.dirname(os.path.realpath(__file__))
|
||||
# Construct 'sdxl_styles.json' path
|
||||
file_path = os.path.join(p, 'sdxl_styles_all.json')
|
||||
|
||||
# Read JSON from file
|
||||
self.json_data = read_json_file(file_path)
|
||||
# Retrieve styles from JSON data
|
||||
styles = read_sdxl_styles(self.json_data)
|
||||
|
||||
return {
|
||||
"required": {
|
||||
"text_positive": ("STRING", {"default": "", "multiline": True}),
|
||||
"text_negative": ("STRING", {"default": "", "multiline": True}),
|
||||
"style": ((styles), ),
|
||||
"log_prompt": (["No", "Yes"], {"default":"No"}),
|
||||
},
|
||||
}
|
||||
|
||||
RETURN_TYPES = ('STRING','STRING',)
|
||||
RETURN_NAMES = ('positive_prompt_text_g','negative_prompt_text_g',)
|
||||
FUNCTION = 'prompt_styler'
|
||||
CATEGORY = 'Style Prompts'
|
||||
|
||||
def prompt_styler(self, text_positive, text_negative, style, log_prompt):
|
||||
# Process and combine prompts in templates
|
||||
# The function replaces the positive prompt placeholder in the template,
|
||||
# and combines the negative prompt with the template's negative prompt, if they exist.
|
||||
positive_prompt, negative_prompt = read_sdxl_templates_replace_and_combine(self.json_data, style, text_positive, text_negative)
|
||||
|
||||
# If logging is enabled (log_prompt is set to "Yes"),
|
||||
# print the style, positive and negative text, and positive and negative prompts to the console
|
||||
if log_prompt == "Yes":
|
||||
print(f"style: {style}")
|
||||
print(f"text_positive: {text_positive}")
|
||||
print(f"text_negative: {text_negative}")
|
||||
print(f"positive_prompt: {positive_prompt}")
|
||||
print(f"negative_prompt: {negative_prompt}")
|
||||
|
||||
return positive_prompt, negative_prompt
|
||||
|
||||
|
||||
class SDXLPromptStylerHorror:
|
||||
|
||||
def __init__(self):
|
||||
@@ -1598,6 +1647,7 @@ class SDXLPromptbyStreetArt:
|
||||
|
||||
|
||||
NODE_CLASS_MAPPINGS = {
|
||||
"SDXLPromptStylerAll": SDXLPromptStylerAll,
|
||||
"SDXLPromptStylerbyArtist": SDXLPromptStylerbyArtist,
|
||||
"SDXLPromptStylerbyCamera": SDXLPromptStylerbyCamera,
|
||||
"SDXLPromptbyCelticArt": SDXLPromptbyCelticArt,
|
||||
@@ -1632,6 +1682,7 @@ NODE_CLASS_MAPPINGS = {
|
||||
}
|
||||
|
||||
NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"SDXLPromptStylerAll": "Prompt Styler All",
|
||||
"SDXLPromptStylerbyArtist": "Prompt Styler Artist",
|
||||
"SDXLPromptStylerbyCamera": "Prompt Styler Camera",
|
||||
"SDXLPromptbyCelticArt": "Prompt Styler Celtic Art",
|
||||
@@ -1663,4 +1714,4 @@ NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"SDXLPromptStylerbyTimeofDay": "Prompt Styler Time of Day",
|
||||
"SDXLPromptbyWildlifeArt": "Prompt Styler Wildlife",
|
||||
"SDXLPromptStylerbyWyvern": "Prompt Styler Wyvern",
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user