Version 1.21.18.1

This commit is contained in:
glibsonoran
2024-10-16 21:22:33 -07:00
parent e9f8b679ae
commit 1f2efdecbb
7 changed files with 259 additions and 7 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 353 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 492 KiB

+97 -4
View File
@@ -1,5 +1,6 @@
from .mng_json import json_manager, helpSgltn, TroubleSgltn
import random
class Tagger:
def __init__(self)-> None:
@@ -160,6 +161,96 @@ class Tagger:
return(output, _help, self.trbl.get_troubles())
class randomOut:
def __init__(self)-> None:
self.trbl = TroubleSgltn()
self.j_mngr = json_manager()
self.help_data = helpSgltn()
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"Text": ("STRING", {"multiline": True, "forceInput": True}),
"randomized_outputs": (['1','2','3','4','5'], {"default": "2"}),
"seed": ("INT", {"default": 9, "min": 0, "max": 0xffffffffffffffff})
},
"hidden": {
"unique_id": "UNIQUE_ID",
}
}
RETURN_TYPES = ("STRING","STRING","STRING","STRING","STRING")
RETURN_NAMES = ("Text_1", "Text_2","Text_3","Text_4","Text_5")
FUNCTION = "gogo"
OUTPUT_NODE = False
CATEGORY = "Plush/Utils"
def gogo(self, Text, unique_id, seed, randomized_outputs=0):
random.seed(seed)
rnd_out = int(randomized_outputs)
int_rnd = random.randint(1, rnd_out)
outputs = ["","","","",""]
if 1 <= int_rnd <= 5:
outputs[int_rnd-1] = Text
out_tuple = tuple(outputs[:5])
return out_tuple
class mixer:
def __init__(self)-> None:
self.trbl = TroubleSgltn()
self.j_mngr = json_manager()
self.help_data = helpSgltn()
@classmethod
def INPUT_TYPES(cls):
return {
"optional": {
"Text_1": ("STRING", {"multiline": True, "forceInput": True}),
"Text_2": ("STRING", {"multiline": True, "forceInput": True}),
"Text_3": ("STRING", {"multiline": True, "forceInput": True}),
"Text_4": ("STRING", {"multiline": True, "forceInput": True}),
"Text_5": ("STRING", {"multiline": True, "forceInput": True}),
"seed": ("INT", {"default": 9, "min": 0, "max": 0xffffffffffffffff})
},
"hidden": {
"unique_id": "UNIQUE_ID",
}
}
RETURN_TYPES = ("STRING","STRING","STRING","STRING","STRING")
RETURN_NAMES = ("Output_1", "Output_2","Output_3","Output_4","Output_5")
FUNCTION = "gogo"
OUTPUT_NODE = False
CATEGORY = "Plush/Utils"
def gogo(self, unique_id, seed, Text_1:str="", Text_2:str="", Text_3:str="", Text_4:str="", Text_5:str=""):
valid_input = [text for text in [Text_1, Text_2, Text_3, Text_4, Text_5] if text] #Fill the list only with actual input data
random.seed(seed)
random.shuffle(valid_input) #randomize list order
padding = 5 - len(valid_input)
valid_input.extend([""] * padding) #pad the outputs with no valid input data with empty strings
out_tuple = tuple(valid_input[:5])
return out_tuple
class mulTextSwitch:
@@ -361,8 +452,9 @@ NODE_CLASS_MAPPINGS = {
"mulTextSwitch": mulTextSwitch,
"ImgTextSwitch": ImgTextSwitch,
"Tagger": Tagger,
"ShowInfo_md": ShowInfo_md,
"ParseJSON": jsonParse
"ParseJSON": jsonParse,
"Random Output": randomOut,
"Random Mixer": mixer
}
@@ -371,7 +463,8 @@ NODE_DISPLAY_NAME_MAPPINGS = {
"mulTextSwitch": "MultiLine Text Switch",
"ImgTextSwitch": "Image & Text Switch",
"Tagger": "Tagger",
"ShowInfo_md": "Display Markdown Text",
"ParseJSON": "Extract JSON data"
"ParseJSON": "Extract JSON data",
"Random Output": "Random Output",
"Random Mixer": "Random Mixer"
}
+1 -1
View File
@@ -17,7 +17,7 @@ if jmanager.on_startup(False):
else:
jmanager.log_events("config.json was not updated")
__version__ ="1.21.18"
__version__ ="1.21.18.1"
print('Plush - Version:', __version__)
+1
View File
File diff suppressed because one or more lines are too long
+67
View File
@@ -114,6 +114,7 @@ class helpSgltn:
self._adv_prompt_help =''
self._tagger_help = ""
self._add_param_help = ""
self._add_params_help = ""
self._extract_json_help = ""
# Empty help text is not a critical issue for the app
if not help_data:
@@ -127,6 +128,7 @@ class helpSgltn:
self._adv_prompt_help = help_data.get('adv_prompt_help', '')
self._tagger_help = help_data.get('tagger_help', '')
self._add_param_help = help_data.get('add_param_help', '')
self._add_params_help = help_data.get('add_params_help', '')
self._extract_json_help = help_data.get('extract_json_help', '')
@property
@@ -153,6 +155,10 @@ class helpSgltn:
def add_param_help(self)->str:
return self._add_param_help
@property
def add_params_help(self)->str:
return self._add_params_help
@property
def extract_json_help (self)->str:
return self._extract_json_help
@@ -1306,6 +1312,67 @@ class json_manager:
self.remove_keys_from_dict(item, keys_to_remove)
def positional_str_to_dict(self, input_data: str, template_dict: Dict[str, Any], comment_char: str = None, delimiter: str = ",") -> List[Dict[str, Any]]:
"""
Parses the input data string to create a list of dictionaries based on a provided template dictionary.
Args:
input_data (str): The raw input string with items separated by newline characters and fields within
each item separated by the specified delimiter. Each item will be parsed and mapped to the keys
in the template dictionary according to their order.
template_dict (Dict[str, Any]): A dictionary template that defines the structure for each output entry.
The order of the keys in this template dictates the assignment of parsed fields from each item
in the input data.
comment_char (str, optional): A character indicating that a line should be treated as a comment and ignored.
Any line beginning with this character will not be processed. If None, all lines are processed.
Default is None.
delimiter (str, optional): The character(s) used to separate fields within each item in input_data.
Default is ",".
Returns:
List[Dict[str, Any]]: A list of dictionaries that match the template structure, with values populated
based on the parsed input data.
Note:
Each field in an item (separated by the specified delimiter)
is mapped to the corresponding key in `template_dict` based on their order. Ensure that the template
dictionary and input data lines are structured consistently with each other.
"""
# Extract the keys from the template dict to map data
template_keys = list(template_dict.keys())
# Split input into lines
lines = input_data.split('\n')
# Initialize the list to hold the resulting dictionaries
result_list = []
self.log_events(f"Received input data of {len(lines)} items.", is_trouble=True)
# Process each line
for line in lines:
# Skip empty lines or lines that begin with the comment character (if set)
line = line.strip() # First remove general whitespace, including newlines
if not line or (comment_char and line.startswith(comment_char)):
continue
line = line.strip(",.;") # Then remove specific characters as needed
# Split line into fields by the specified delimiter
fields = line.split(delimiter)
# Create the dictionary structure based on the template
entry = template_dict.copy()
for i, key in enumerate(template_keys):
if i < len(fields):
# Assign the parsed value to the corresponding template key
entry[key] = self.infer_type(fields[i].strip())
result_list.append(entry)
return result_list
def insert_text_into_dict(self, input_data:Union[str, list[str]], template_dict:dict, insert_key:str, delimiter:str="|"):
"""
Processes input_data to create a list of dictionaries based on the template_dict. The input_data can be a
+93 -2
View File
@@ -640,6 +640,95 @@ class Enhancer:
return (CGPT_prompt, instruction, CGPT_styleInfo, _help, self.trbl.get_troubles())
class addParameters:
##New##
def __init__(self):
#instantiate Configuration and Help data classes
self.cFig = cFigSingleton()
self.help_data = helpSgltn()
self.j_mngr = json_manager()
self.trbl = TroubleSgltn()
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"Parameters": ("STRING", {"multiline": True, "default": ""}),
"Save_to_file": ("BOOLEAN", {"default": False}),
"File_name": ("STRING", {"default": ""})
},
"hidden": {
"unique_id": "UNIQUE_ID",
}
}
RETURN_TYPES = ("LIST", "STRING", "STRING")
RETURN_NAMES = ("Add_Parameter","Help","Troubleshooting")
FUNCTION = "gogo"
OUTPUT_NODE = False
CATEGORY = "Plush/Prompt"
def gogo(self, Parameters, Save_to_file, File_name:bool, unique_id=None):
self.trbl.reset(f"Add Parameters, Node: {unique_id}")
_help = self.help_data.add_params_help
param_list = []
#Create path and dir for saved .txt files
write_dir = ''
comfy_dir = self.j_mngr.comfy_dir
if comfy_dir:
output_dir = self.j_mngr.find_child_directory(comfy_dir,'output')
if output_dir:
write_dir = self.j_mngr.find_child_directory(output_dir, 'PlushFiles',True) #Setting argument to True means dir will be created if not present
if not write_dir:
self.j_mngr.log_events('Unable to find or create PlushFiles directory. Unable to write files',
TroubleSgltn.Severity.WARNING,
True)
else:
self.j_mngr.log_events('Unable to find output directory, Unable to write files',
TroubleSgltn.Severity.WARNING,
True)
else:
self.j_mngr.log_events('Unable to find ComfyUI directory. Unable to write files.',
TroubleSgltn.Severity.WARNING,
True)
if Save_to_file and write_dir:
working_file_name = self.j_mngr.generate_unique_filename("txt", File_name + '_param_')
working_file_path = self.j_mngr.append_filename_to_path(write_dir,working_file_name)
self.j_mngr.write_string_to_file(Parameters,working_file_path)
self.j_mngr.log_events(f"Parameter file: '{working_file_name}' successfully written to directory [{write_dir}]",
is_trouble=True)
if Parameters:
template_dict = {"param": None, "value": None}
param_list = self.j_mngr.positional_str_to_dict(Parameters,template_dict,"#","::") #Parses the Parameters data and puts the result in a list of dicts
if not param_list:
self.j_mngr.log_events("Parameters not processed",
TroubleSgltn.Severity.ERROR,
True)
return(param_list,_help,self.trbl.get_troubles())
else:
self.j_mngr.log_events("No paramter data provided.",
TroubleSgltn.Severity.INFO,
True)
return(param_list,_help,self.trbl.get_troubles())
self.j_mngr.log_events(f"Parameters added: {str(param_list)}",
is_trouble=True)
return(param_list,_help,self.trbl.get_troubles())
class addParams:
def __init__(self):
#instantiate Configuration and Help data classes
@@ -1455,7 +1544,8 @@ NODE_CLASS_MAPPINGS = {
"AdvPromptEnhancer": AdvPromptEnhancer,
"DalleImage": DalleImage,
"Plush-Exif Wrangler" :ImageInfoExtractor,
"Additional Parameter" :addParams
"Additional Parameter" :addParams,
"Add Parameters": addParameters
}
# A dictionary that contains the friendly/humanly readable titles for the nodes
@@ -1465,6 +1555,7 @@ NODE_DISPLAY_NAME_MAPPINGS = {
"AdvPromptEnhancer": "Advanced Prompt Enhancer",
"DalleImage": "OAI Dall_e Image",
"ImageInfoExtractor": "Exif Wrangler",
"Additional Parameter": "Additional Parameter"
"Additional Parameter": "Additional Parameter",
"Add Parameters": "Add Parameters"
}