From 6f1fac147e4e8203d1f3d5feea62b61a16cbe39d Mon Sep 17 00:00:00 2001 From: Ardenius Date: Fri, 15 Nov 2024 23:58:33 +0300 Subject: [PATCH] added experimental ARD Prompt Travel, ARD Counter, and updated ARD Save Image and ARD text box. --- .gitignore | 1 + ard_counter.py | 34 ++++++------- ard_prompt_travel.py | 18 ++++--- ard_save_image.py | 118 ++++++++++++++++++++++++++++--------------- ard_text_box.py | 6 +-- 5 files changed, 107 insertions(+), 70 deletions(-) diff --git a/.gitignore b/.gitignore index 282f024..93ea516 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ /ard_data/ard_counter.json /ard_data/temp_data.json /ard_data/xy_data.json +/ard_video_combine.py diff --git a/ard_counter.py b/ard_counter.py index ae46723..c1e1235 100644 --- a/ard_counter.py +++ b/ard_counter.py @@ -2,7 +2,7 @@ @author: initials AMA @title: Ardenius @nickname: Ardenius -@description: ARD Counter: keeps increasing x_count by x_input until x_total is reached then resets to zero +@description: ARD Counter (experimental): keeps counting x_input until x_total is reached then it resets to zeros """ # licensed under General Public License v3.0 all rights reserved © 2024 @@ -29,8 +29,11 @@ class ARD_COUNTER: def INPUT_TYPES(cls): return { "required": { - "x_input": ("FLOAT", {"default": 1, "tooltip": "input a float that increments to be added to x_count"}), - "x_total": ("FLOAT", {"default": 1, "tooltip": "total a float when reached resets x_count to zeros"}) + "x_input": ("FLOAT", {"default": 0, "tooltip": "input a float that increments to be added to x_count"}), + "x_total": ("FLOAT", {"default": 0, "tooltip": "total a float when reached resets x_count to zeros"}) + }, + "optional": { + "print_output": (["enabled", "disabled"], {"default": "enabled"}) } } @@ -39,9 +42,9 @@ class ARD_COUNTER: FUNCTION = "ard_counter" CATEGORY = "Ardenius" - DESCRIPTION = "ARD Counter: keeps counting integer number increasing by Cx and zeros if total is reached" + DESCRIPTION = "ARD Counter (experimental): keeps counting x_input until x_total is reached then it resets to zeros" - def ard_counter(self, x_input, x_total): + def ard_counter(self, x_input, x_total, print_output): x_count_int = 0 x_count_float = 0.0 @@ -77,25 +80,22 @@ class ARD_COUNTER: x_count_float_old = counter_dict.get("x_count_float", 0.0) x_count_int_old = counter_dict.get("x_count_int_old", 0) - if x_input is not None and 0.0 < x_input < x_total: + if x_input > 0 and x_count_float < x_total: + x_count_float = x_count_float_old + x_input - - if x_count_float > x_total: - x_input = 0.0 - x_total = 0.0 - x_count_float = 0.0 - x_count_int = 0 - # print(f'\n***\nard_counter reset to zero:\nx count float: {x_count_float}\nx input: {x_input}\nx total: {x_total}\n***\n') - x_count_int = int(x_count_float) + counter_dict["x_input"] = x_input counter_dict["x_total"] = x_total counter_dict["x_count_int"] = x_count_int counter_dict["x_count_float"] = x_count_float ard_lib.save_dict_to_json(counter_dict, ard_counter_json) - # print(f'\n***\nx count float: {x_count_float}\nx input: {x_input}\nx total: {x_total}\n***\n') + if print_output == "enabled": + print(f'\n***\nx count float: {x_count_float}\nx input: {x_input}\nx total: {x_total}\n***\n') else: - x_count_float = x_count_float_old - x_count_int = x_count_int_old + if print_output == "enabled": + print(f'\n***\nard_counter resetting to zero:\nlast x count float: {x_count_float}\nx total: {x_total}\n***\n') + if os.path.exists(ard_counter_json): + os.remove(ard_counter_json) return (x_count_int, x_count_float) diff --git a/ard_prompt_travel.py b/ard_prompt_travel.py index 83941e8..111f0ef 100644 --- a/ard_prompt_travel.py +++ b/ard_prompt_travel.py @@ -2,7 +2,7 @@ @author: initials AMAA @title: Ardenius AI @nickname: Ardenius -@description: ARD Prompt Travel: add text box takes input text adds it to contained text and outputs a string of text. controlled through counter. +@description: ARD Prompt Travel (experimental): add text box takes input text adds it to contained text and outputs a string of text. controlled through counter. """ # licensed under General Public License v3.0 all rights reserved © 2024 # Owner initials: AMAA @@ -27,23 +27,25 @@ class ARD_PROMPT_TRAVEL: "add_text": ("STRING", {"multiline": True, "dynamicPrompts": True, "default": "", "tooltip": "enter your text here to be added to previous input text"}) }, "optional": { - "xcount": ("FLOAT", {"default": 1.0, "step": 1.0}), - "from_xcount": ("FLOAT", {"default": 1.0, "step": 1.0}), - "to_xcount": ("FLOAT", {"default": 1.0, "step": 1.0}) + "xcount": ("FLOAT", {"default": 0.0, "step": 0.1}), + "from_xcount": ("FLOAT", {"default": 0.0, "step": 0.1}), + "to_xcount": ("FLOAT", {"default": 0.0, "step": 0.1}), + "print_output": (["enabled", "disabled"], {"default": "enabled"}) } } - RETURN_NAMES = ("string_out","xcount") + RETURN_NAMES = ("string_out","xcount",) RETURN_TYPES = ("STRING", "FLOAT",) FUNCTION = "ard_prompt_travel" CATEGORY = "Ardenius" - DESCRIPTION = "ARD Prompt Travel: add text box takes input text adds it to contained text and outputs a string of text. controlled through counter" + DESCRIPTION = "ARD Prompt Travel (experimental): add text box takes input text adds it to contained text and outputs a string of text. controlled through counter" - def ard_prompt_travel(self, input_text, add_text, xcount, from_xcount, to_xcount): + def ard_prompt_travel(self, input_text, add_text, xcount, from_xcount, to_xcount, print_output): if isinstance(input_text, str) and isinstance(add_text, str) and (from_xcount <= xcount <= to_xcount) and xcount > 0.0: text = input_text + ' ' + add_text - print(f"\n***\nARD Prompt Travel: {xcount}: executing prompt:\n{text}\n***\n") + if print_output == "enabled": + print(f"\n***\nARD Prompt Travel: frame: {xcount}: \nexecuting prompt:\n{text}\n***\n") else: text = str(input_text) return (text, xcount) \ No newline at end of file diff --git a/ard_save_image.py b/ard_save_image.py index b36d9f5..f02916b 100644 --- a/ard_save_image.py +++ b/ard_save_image.py @@ -25,6 +25,7 @@ from PIL.PngImagePlugin import PngInfo import folder_paths from comfy.cli_args import args import ard_lib +from custom_nodes.comfyui_controlnet_aux.src.custom_detectron2.config import instantiate current_directory = os.path.dirname(os.path.abspath(__file__)) ard_data = os.path.join(current_directory, "/ard_data") @@ -179,7 +180,7 @@ class ARD_SAVE_IMAGE: if show_terminal_notifications == 'enabled': print(f"\nARD Save Image: workflow metadata added to image {counter} ") - metadata.add_text("generation software", 'generated using Ardenius AI ARD Save Image found at https://ko-fi.com/ardenius') + metadata.add_text("generation software", 'generated using Ardenius AI ARD ComfyUI Nodes found at https://ko-fi.com/ardenius email: ardenius7@gmail.com') if show_terminal_notifications == 'enabled': print("ARD Save Image: generation software info added to image") else: @@ -215,7 +216,7 @@ class ARD_SAVE_IMAGE: txt_prompt_file = f"{filename_prefix}{counter}{filename_postfix}.txt" txt_prompt_file_path = os.path.join(full_output_folder, txt_prompt_file) with open(txt_prompt_file_path, 'w', buffering=1) as f_txt: - prompt_txt = basic_meta['positive'] + prompt_txt = str(basic_meta['positive']) f_txt.write(prompt_txt) counter += 1 @@ -238,6 +239,8 @@ class ARD_SAVE_IMAGE: def prompt_get_values(s, prompt_in): prompt_keys1 = prompt_in.keys() prompt_dict = {} + positive = "" + negative = "" positive_not_found = True negative_not_found = True for keys in prompt_keys1: @@ -246,35 +249,42 @@ class ARD_SAVE_IMAGE: for sub_sub_keys in prompt_in[keys][sub_keys]: # print(f'sub sub key: {sub_sub_keys}') if sub_sub_keys == 'seed': - seed = prompt_in[keys][sub_keys]['seed'] + seed = prompt_in[keys][sub_keys].get('seed', None) seed = s.if_list(seed) - prompt_dict.update({"seed": seed}) + if isinstance(seed, int) and seed is not None: + prompt_dict.update({"seed": seed}) if sub_sub_keys == 'steps': - steps = prompt_in[keys][sub_keys]['steps'] + steps = prompt_in[keys][sub_keys].get('steps', None) steps = s.if_list(steps) - prompt_dict.update({"steps": steps}) + if steps is not None and isinstance(steps, int): + prompt_dict.update({"steps": steps}) if sub_sub_keys == 'cfg': - cfg = prompt_in[keys][sub_keys]['cfg'] + cfg = prompt_in[keys][sub_keys].get('cfg', None) cfg = s.if_list(cfg) - prompt_dict.update({"cfg": cfg}) + if cfg is not None and isinstance(cfg, float): + prompt_dict.update({"cfg": cfg}) if sub_sub_keys == 'sampler_name': - sampler_name = prompt_in[keys][sub_keys]['sampler_name'] + sampler_name = prompt_in[keys][sub_keys].get('sampler_name', None) sampler_name = s.if_list(sampler_name) - prompt_dict.update({"sampler_name": sampler_name}) + if sampler_name is not None and isinstance(sampler_name, str): + prompt_dict.update({"sampler_name": sampler_name}) if sub_sub_keys == 'scheduler': - scheduler = prompt_in[keys][sub_keys]['scheduler'] + scheduler = prompt_in[keys][sub_keys].get('scheduler', None) scheduler = s.if_list(scheduler) - prompt_dict.update({"scheduler": scheduler}) + if scheduler is not None and isinstance(scheduler, str): + prompt_dict.update({"scheduler": scheduler}) if sub_sub_keys == 'denoise': - denoise = prompt_in[keys][sub_keys]['denoise'] + denoise = prompt_in[keys][sub_keys].get('denoise', None) denoise = s.if_list(denoise) - prompt_dict.update({"denoise": denoise}) + if denoise is not None and isinstance(denoise, float): + prompt_dict.update({"denoise": denoise}) if sub_sub_keys == 'ckpt_name': - ckpt_name = prompt_in[keys][sub_keys]['ckpt_name'] + ckpt_name = prompt_in[keys][sub_keys].get('ckpt_name', None) ckpt_name = s.if_list(ckpt_name) - prompt_dict.update({"ckpt_name": str(ckpt_name)}) - if sub_sub_keys == 'UnetLoaderGGUF': - ckpt_name = prompt_in[keys][sub_keys]['widgets_values'] + if ckpt_name is not None and isinstance(ckpt_name, str): + prompt_dict.update({"ckpt_name": str(ckpt_name)}) + if sub_sub_keys == 'MODEL': + ckpt_name = prompt_in[keys][sub_keys].get("MODEL", "not_found") ckpt_name = s.if_list(ckpt_name) prompt_dict.update({"ckpt_name": str(ckpt_name)}) if sub_sub_keys == 'lora_name': @@ -286,29 +296,53 @@ class ARD_SAVE_IMAGE: vae = prompt_in[keys][sub_keys]['vae'] vae = s.if_list(vae) prompt_dict.update({"vae": vae}) - if sub_sub_keys == 'pos_text': - pos_init = prompt_in[keys][sub_keys]['pos_text'] - if isinstance(pos_init, str): - positive = prompt_in[keys][sub_keys]['pos_text'] - positive = s.if_list(positive) - prompt_dict.update({"positive": positive}) - positive_not_found = False - if (sub_sub_keys == 'text' and positive_not_found): - positive = prompt_in[keys][sub_keys]['text'] - positive = s.if_list(positive) - prompt_dict.update({"positive": positive}) - positive_not_found = False - if sub_sub_keys == 'neg_text': - neg_init = prompt_in[keys][sub_keys]['neg_text'] - if isinstance(neg_init, str): - negative = prompt_in[keys][sub_keys]['neg_text'] - negative = s.if_list(negative) - prompt_dict.update({"negative": negative}) - negative_not_found = False - if sub_sub_keys == 'text' and negative_not_found: - negative = prompt_in[keys][sub_keys]['text'] - negative = s.if_list(negative) - prompt_dict.update({"negative": negative}) - negative_not_found = False + if sub_sub_keys == 'pos_text' or sub_sub_keys == "string_out" or "text" or "add_text" or sub_sub_keys == "positive" or sub_sub_keys == "pos_prompt" or sub_sub_keys == "input_text": + search_keys = ["pos_prompt", "pos_text", "positive", "text", "add_text", "input_text", "string_out"] + found_in_text = False + for search_item in search_keys: + get_value = prompt_in[keys][sub_keys].get(search_item, None) + if get_value is not None : + if isinstance(get_value, str) and get_value != "": + if get_value not in positive: + if positive != "" and search_item == "text": + pass + else: + positive += str(get_value) + " " + prompt_dict.update({"positive": positive}) + positive_not_found = False + if search_item == "text": + found_in_text = True + # print(f'\npositive in search: {positive}') + + if positive == "" and positive_not_found and sub_sub_keys == "text": + positive_init = prompt_in[keys][sub_keys].get("text", "") + if isinstance(positive_init, str) and positive_init != "": + positive = positive_init + " " + prompt_dict.update({"positive": positive}) + positive_not_found = False + # print(f'\npositive in text: {positive}') + + if sub_sub_keys == 'neg_text' or sub_sub_keys == 'text' or sub_sub_keys == "neg_prompt" or sub_sub_keys == "negative": + search_keys = ["neg_prompt", "negative", "text", "neg_text"] + for search_item in search_keys: + get_value = prompt_in[keys][sub_keys].get(search_item, None) + if get_value is not None: + if isinstance(get_value, str) and get_value != "" and get_value not in positive: + negative += str(get_value) + " " + if negative in positive: + positive = positive.replace(negative, "") + prompt_dict.update({"positive": positive}) + prompt_dict.update({"negative": negative}) + if search_item != "neg_text": + negative_not_found = False + # print(f'\nnegative in search: {negative}\n') + + if negative != "" and negative_not_found and sub_sub_keys == "text": + negative_init = prompt_in[keys][sub_keys].get("text", "") + if isinstance(negative_init, str) and negative_init != "": + negative += negative_init + " " + prompt_dict.update({"negative": negative}) + negative_not_found = False + # print(f'\nnegative in text: {negative}\n') return prompt_dict # my_code_end diff --git a/ard_text_box.py b/ard_text_box.py index cc6d9c2..7d1bc4e 100644 --- a/ard_text_box.py +++ b/ard_text_box.py @@ -23,7 +23,7 @@ class ARD_TEXT_BOX: def INPUT_TYPES(cls): return { "required": { - "text": ("STRING", {"multiline": True, "dynamicPrompts": True, "tooltip": "enter your text here"}), + "input_text": ("STRING", {"multiline": True, "dynamicPrompts": True, "tooltip": "enter your text here"}), "ard_counter": ("FLOAT",{"default": 1.0}) } } @@ -35,6 +35,6 @@ class ARD_TEXT_BOX: CATEGORY = "Ardenius" DESCRIPTION = "text box takes input text outputs a string of text." - def ard_text_box(self, text, ard_counter): + def ard_text_box(self, input_text, ard_counter): - return (text, ard_counter) \ No newline at end of file + return (input_text, ard_counter) \ No newline at end of file