Removed the Prompt Styler nodes

This commit is contained in:
HavocsCall
2025-04-09 10:04:38 -04:00
parent e7167119bc
commit 8f01245ef4
6 changed files with 1 additions and 145 deletions
+1 -2
View File
@@ -1,2 +1 @@
*__pycache__
*/Styler_Data/*/*
*__pycache__
-3
View File
@@ -14,9 +14,6 @@
- Int to Float
- Int to String
### Prompt Styler Nodes
- Prompt Stylers
### Switch Nodes
- Clip Switch
- Conditioning Switch
-21
View File
@@ -21,27 +21,6 @@ git clone https://github.com/HavocsCall/comfyui_HavocsCall_Custom_Nodes.git
- Int to Float - Converts an `INTEGER` to a `FLOAT`.
- Int to String - Converts an `INTEGER` to a `STRING`.
### Prompt Styler Nodes
- json based Prompt Styler - Create a .json file in the `Styler_Data` folder formatted like this:
```json
[
{
"name": "None",
"positive_prompt": "{prompt}",
"negative_prompt": "{prompt}"
},
{
"name": "Example",
"positive_prompt": "{prompt}, Example",
"negative_prompt": "Example, {prompt}"
},
{
etc...
}
]
```
Each .json file will create it's own node with the name of the .json file + Styler.
### Switch Nodes
- Clip Switch - Switches between two `CLIPS`.
- Conditioning Switch - Switches between two `CONDITIONING`.
-9
View File
@@ -1,6 +1,5 @@
from .nodes.Basic_Nodes import *
from .nodes.Conversion_Nodes import *
from .nodes.Prompt_Styler_Nodes import *
from .nodes.Switch_Nodes import *
NODE_CLASS_MAPPINGS = {
@@ -18,10 +17,6 @@ NODE_CLASS_MAPPINGS = {
"Float to String": HC_Float_to_String,
"Int to Float": HC_Int_to_Float,
"Int to String": HC_Int_to_String,
#------------------------------------------------------------------------------------------#
#-----Prompt Styler Nodes-----
**{name.replace(' ', ''): type(name.replace(' ', ''), (SDXLPromptStyler, ), {'menus': menus}) for name, menus in NODES.items()},
#------------------------------------------------------------------------------------------#
#-----Switch Nodes-----
@@ -49,10 +44,6 @@ NODE_DISPLAY_NAME_MAPPINGS = {
"Float to String": "Float to String",
"Int to Float": "Int to Float",
"Int to String": "Int to String",
#------------------------------------------------------------------------------------------#
#-----Prompt Styler Nodes-----
**{name.replace(' ', ''): name for name in NODES.keys()},
#------------------------------------------------------------------------------------------#
#-----Switch Nodes-----
-98
View File
@@ -1,98 +0,0 @@
import json
import pathlib
from collections import defaultdict
#------------------------------------------------------------------------------------------#
#-----Prompt Styler-----
# This is copied from https://github.com/TripleHeadedMonkey/ComfyUI_MileHighStyler, thank you very much.
# I am learning about this and will recreate it in the future.
class Template:
def __init__(self, positive_prompt, negative_prompt, **kwargs):
self.positive_prompt = positive_prompt
self.negative_prompt = negative_prompt
def replace_prompts(self, positive_prompt, negative_prompt):
positive_result = self.positive_prompt.replace('{prompt}', positive_prompt)
negative_result = self.negative_prompt.replace('{prompt}', negative_prompt)
return positive_result, negative_result
class StylerData:
def __init__(self, datadir=None):
self._data = defaultdict(dict)
datadir = pathlib.Path(__file__).parent / 'styler_data'
for j in datadir.glob('*/*.json'):
try:
with j.open('r') as f:
content = json.load(f)
group = j.parent.name
for template in content:
self._data[group][template['name']] = Template(**template)
except PermissionError:
print(f"Warning: No read permissions for file {j}")
except KeyError:
print(f"Warning: Malformed data in {j}")
def __getitem__(self, item):
return self._data[item]
def keys(self):
return self._data.keys()
styler_data = StylerData()
class SDXLPromptStyler:
menus = ()
@classmethod
def INPUT_TYPES(cls):
menus = {menu: (list(styler_data[menu].keys()), ) for menu in cls.menus}
inputs = {
"required": {
"text_positive": ("STRING", {"default": "", "forceInput": True}),
"text_negative": ("STRING", {"default": "", "forceInput": True}),
**menus,
},
}
return inputs
RETURN_TYPES = ('STRING','STRING',)
RETURN_NAMES = ('text_positive','text_negative',)
FUNCTION = 'prompt_styler'
CATEGORY = 'HavocsCall/Prompt Stylers'
def prompt_styler(self, text_positive, text_negative, **kwargs):
text_positive_styled, text_negative_styled = text_positive, text_negative
for menu, selection in kwargs.items():
text_positive_styled, text_negative_styled = styler_data[menu][selection].replace_prompts(text_positive_styled, text_negative_styled)
return text_positive_styled, text_negative_styled
NODES = {
# define your nodes here
# first the friendly name, then a sequence of strings
# corresponding to subdirectories of the data dir.
# individual stylers have one menu item
# build them automatically from the scanned directories
**{f'{name.title()} Styler': (name, ) for name in styler_data.keys()},
# alternatively you can list every single-menu node like this:
# 'Camera Styler': ('camera', ),
# etc...
# perfection styler has everything except artist and milehigh
# we can define it by excluding those
# downside of this method is you have no control over the order
#'Perfection Styler': [x for x in styler_data.keys() if x not in ('artist', 'milehigh')],
# alternatively define it manually, and you can reorder the items
}
for k, v in NODES.items():
assert not isinstance(v, str), f"Error: {k} has a string instead of a sequence for its menu list. Did you forget a comma?"
-12
View File
@@ -1,12 +0,0 @@
[
{
"name": "None",
"positive_prompt": "{prompt}",
"negative_prompt": "{prompt}"
},
{
"name": "Example",
"positive_prompt": "{prompt}, Example",
"negative_prompt": "Example, {prompt}"
}
]