From 31a0fbf1ad0db90cd439c0d072de7753c5a28d95 Mon Sep 17 00:00:00 2001 From: DepFA <35278260+dfaker@users.noreply.github.com> Date: Sun, 25 Sep 2022 06:55:33 +0100 Subject: [PATCH 1/7] add attribute to custom script controls --- modules/scripts.py | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/scripts.py b/modules/scripts.py index 9ab207dc..202374e6 100644 --- a/modules/scripts.py +++ b/modules/scripts.py @@ -119,6 +119,7 @@ class ScriptRunner: continue for control in controls: + control.custom_script_source = os.path.basename(script.filename) control.visible = False inputs += controls From 50ae19acf6003708390ae6696e833cf596621882 Mon Sep 17 00:00:00 2001 From: DepFA <35278260+dfaker@users.noreply.github.com> Date: Sun, 25 Sep 2022 06:56:50 +0100 Subject: [PATCH 2/7] add custom script source to config path keys --- modules/ui.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/ui.py b/modules/ui.py index 91f07cd5..54c80df6 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -1040,6 +1040,9 @@ def create_ui(txt2img, img2img, run_extras, run_pnginfo): def loadsave(path, x): def apply_field(obj, field, condition=None): key = path + "/" + field + + if getattr(obj,'custom_script_source',None) is not None: + key = 'customscript/' + obj.custom_script_source + '/' + key if getattr(obj,'do_not_save_to_config',False): return From 40166dbf086f49b3566ac5a2003dd0a980dc29e0 Mon Sep 17 00:00:00 2001 From: Eyrie Date: Sun, 25 Sep 2022 12:29:40 +0200 Subject: [PATCH 3/7] Added job_id pattern for directories --- javascript/hints.js | 1 + modules/images.py | 1 + modules/shared.py | 6 +++++- webui.py | 1 + 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/javascript/hints.js b/javascript/hints.js index b43f7bbd..a5311eaa 100644 --- a/javascript/hints.js +++ b/javascript/hints.js @@ -60,6 +60,7 @@ titles = { "Images filename pattern": "Use following tags to define how filenames for images are chosen: [steps], [cfg], [prompt], [prompt_spaces], [width], [height], [styles], [sampler], [seed], [model_hash], [prompt_words], [date]; leave empty for default.", "Directory name pattern": "Use following tags to define how subdirectories for images and grids are chosen: [steps], [cfg], [prompt], [prompt_spaces], [width], [height], [styles], [sampler], [seed], [model_hash], [prompt_words], [date]; leave empty for default.", "Max prompt words": "Set the maximum number of words to be used in the [prompt_words] option; ATTENTION: If the words are too long, they may exceed the maximum length of the file path that the system can handle", + "Length of job id": "Sets the number of characters to be used for the [job_id] option", "Loopback": "Process an image, use it as an input, repeat.", "Loops": "How many times to repeat processing an image and using it as input for the next iteration", diff --git a/modules/images.py b/modules/images.py index 642cde36..e85c71d5 100644 --- a/modules/images.py +++ b/modules/images.py @@ -295,6 +295,7 @@ def apply_filename_pattern(x, p, seed, prompt): x = x.replace("[model_hash]", shared.sd_model.sd_model_hash) x = x.replace("[date]", datetime.date.today().isoformat()) + x = x.replace("[job_id]", shared.state.job_id) if cmd_opts.hide_ui_dir_config: x = re.sub(r'^[\\/]+|\.{2,}[\\/]+|[\\/]+\.{2,}', '', x) diff --git a/modules/shared.py b/modules/shared.py index 1ce6eefc..014febcc 100644 --- a/modules/shared.py +++ b/modules/shared.py @@ -4,6 +4,7 @@ import json import os import gradio as gr import tqdm +import random import modules.artists from modules.paths import script_path, sd_path @@ -65,6 +66,7 @@ class State: job = "" job_no = 0 job_count = 0 + job_id = 0 sampling_step = 0 sampling_steps = 0 current_latent = None @@ -78,6 +80,8 @@ class State: self.job_no += 1 self.sampling_step = 0 self.current_image_sampling_step = 0 + def gen_job_id(self): + return ''.join(random.choices('0123456789abcdefghijklmnopqrstuvwxyz', k=opts.job_id_length)) state = State() @@ -115,7 +119,6 @@ def options_section(section_identifer, options_dict): return options_dict - hide_dirs = {"visible": not cmd_opts.hide_ui_dir_config} options_templates = {} @@ -156,6 +159,7 @@ options_templates.update(options_section(('saving-to-dirs', "Saving to a directo "grid_save_to_dirs": OptionInfo(False, "Save grids to subdirectory"), "directories_filename_pattern": OptionInfo("", "Directory name pattern"), "directories_max_prompt_words": OptionInfo(8, "Max prompt words", gr.Slider, {"minimum": 1, "maximum": 20, "step": 1}), + "job_id_length": OptionInfo(5, "Length of job id", gr.Slider, {"minimum": 5, "maximum": 20, "step": 1}), })) options_templates.update(options_section(('upscaling', "Upscaling"), { diff --git a/webui.py b/webui.py index 64c9d462..d0a4e00f 100644 --- a/webui.py +++ b/webui.py @@ -50,6 +50,7 @@ def wrap_gradio_gpu_call(func): shared.state.sampling_step = 0 shared.state.job_count = -1 shared.state.job_no = 0 + shared.state.job_id = shared.state.gen_job_id() shared.state.current_latent = None shared.state.current_image = None shared.state.current_image_sampling_step = 0 From ba34b790d3ea776d9b91278630b9166d3e6dbb69 Mon Sep 17 00:00:00 2001 From: Eyrie Date: Sun, 25 Sep 2022 12:45:18 +0200 Subject: [PATCH 4/7] Added hints for file & dir patterns --- javascript/hints.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/javascript/hints.js b/javascript/hints.js index a5311eaa..ff6a49a8 100644 --- a/javascript/hints.js +++ b/javascript/hints.js @@ -57,8 +57,8 @@ titles = { "Interrogate": "Reconstruct prompt from existing image and put it into the prompt field.", - "Images filename pattern": "Use following tags to define how filenames for images are chosen: [steps], [cfg], [prompt], [prompt_spaces], [width], [height], [styles], [sampler], [seed], [model_hash], [prompt_words], [date]; leave empty for default.", - "Directory name pattern": "Use following tags to define how subdirectories for images and grids are chosen: [steps], [cfg], [prompt], [prompt_spaces], [width], [height], [styles], [sampler], [seed], [model_hash], [prompt_words], [date]; leave empty for default.", + "Images filename pattern": "Use following tags to define how filenames for images are chosen: [steps], [cfg], [prompt], [prompt_spaces], [width], [height], [styles], [sampler], [seed], [model_hash], [prompt_words], [date], [job_id]; leave empty for default.", + "Directory name pattern": "Use following tags to define how subdirectories for images and grids are chosen: [steps], [cfg], [prompt], [prompt_spaces], [width], [height], [styles], [sampler], [seed], [model_hash], [prompt_words], [date], [job_id]; leave empty for default.", "Max prompt words": "Set the maximum number of words to be used in the [prompt_words] option; ATTENTION: If the words are too long, they may exceed the maximum length of the file path that the system can handle", "Length of job id": "Sets the number of characters to be used for the [job_id] option", From e13912dfde4d3d6a8a8bbcd1f54275b17eca13a1 Mon Sep 17 00:00:00 2001 From: Eyrie Date: Sun, 25 Sep 2022 12:56:13 +0200 Subject: [PATCH 5/7] fix formatting --- modules/shared.py | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/shared.py b/modules/shared.py index 014febcc..527c8527 100644 --- a/modules/shared.py +++ b/modules/shared.py @@ -117,6 +117,7 @@ def options_section(section_identifer, options_dict): for k, v in options_dict.items(): v.section = section_identifer + return options_dict hide_dirs = {"visible": not cmd_opts.hide_ui_dir_config} From 4c3d4aad60ffd701967ce1d358c37a33c941bb44 Mon Sep 17 00:00:00 2001 From: Eyrie Date: Sun, 25 Sep 2022 12:56:32 +0200 Subject: [PATCH 6/7] fix formatting --- modules/shared.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/shared.py b/modules/shared.py index 527c8527..01076be5 100644 --- a/modules/shared.py +++ b/modules/shared.py @@ -117,9 +117,9 @@ def options_section(section_identifer, options_dict): for k, v in options_dict.items(): v.section = section_identifer - return options_dict + hide_dirs = {"visible": not cmd_opts.hide_ui_dir_config} options_templates = {} From 1877a3767ed7502c25245c3de3449b22067db74c Mon Sep 17 00:00:00 2001 From: Eyrie Date: Sun, 25 Sep 2022 14:45:20 +0200 Subject: [PATCH 7/7] Changed job_id to timestamp --- javascript/hints.js | 6 ++---- modules/images.py | 2 +- modules/shared.py | 9 ++++----- webui.py | 2 +- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/javascript/hints.js b/javascript/hints.js index ff6a49a8..ed79796f 100644 --- a/javascript/hints.js +++ b/javascript/hints.js @@ -57,15 +57,13 @@ titles = { "Interrogate": "Reconstruct prompt from existing image and put it into the prompt field.", - "Images filename pattern": "Use following tags to define how filenames for images are chosen: [steps], [cfg], [prompt], [prompt_spaces], [width], [height], [styles], [sampler], [seed], [model_hash], [prompt_words], [date], [job_id]; leave empty for default.", - "Directory name pattern": "Use following tags to define how subdirectories for images and grids are chosen: [steps], [cfg], [prompt], [prompt_spaces], [width], [height], [styles], [sampler], [seed], [model_hash], [prompt_words], [date], [job_id]; leave empty for default.", + "Images filename pattern": "Use following tags to define how filenames for images are chosen: [steps], [cfg], [prompt], [prompt_spaces], [width], [height], [styles], [sampler], [seed], [model_hash], [prompt_words], [date], [job_timestamp]; leave empty for default.", + "Directory name pattern": "Use following tags to define how subdirectories for images and grids are chosen: [steps], [cfg], [prompt], [prompt_spaces], [width], [height], [styles], [sampler], [seed], [model_hash], [prompt_words], [date], [job_timestamp]; leave empty for default.", "Max prompt words": "Set the maximum number of words to be used in the [prompt_words] option; ATTENTION: If the words are too long, they may exceed the maximum length of the file path that the system can handle", - "Length of job id": "Sets the number of characters to be used for the [job_id] option", "Loopback": "Process an image, use it as an input, repeat.", "Loops": "How many times to repeat processing an image and using it as input for the next iteration", - "Style 1": "Style to apply; styles have components for both positive and negative prompts and apply to both", "Style 2": "Style to apply; styles have components for both positive and negative prompts and apply to both", "Apply style": "Insert selected styles into prompt fields", diff --git a/modules/images.py b/modules/images.py index e85c71d5..ae0e6304 100644 --- a/modules/images.py +++ b/modules/images.py @@ -295,7 +295,7 @@ def apply_filename_pattern(x, p, seed, prompt): x = x.replace("[model_hash]", shared.sd_model.sd_model_hash) x = x.replace("[date]", datetime.date.today().isoformat()) - x = x.replace("[job_id]", shared.state.job_id) + x = x.replace("[job_timestamp]", shared.state.job_timestamp) if cmd_opts.hide_ui_dir_config: x = re.sub(r'^[\\/]+|\.{2,}[\\/]+|[\\/]+\.{2,}', '', x) diff --git a/modules/shared.py b/modules/shared.py index 01076be5..c32da110 100644 --- a/modules/shared.py +++ b/modules/shared.py @@ -4,7 +4,7 @@ import json import os import gradio as gr import tqdm -import random +import datetime import modules.artists from modules.paths import script_path, sd_path @@ -66,7 +66,7 @@ class State: job = "" job_no = 0 job_count = 0 - job_id = 0 + job_timestamp = 0 sampling_step = 0 sampling_steps = 0 current_latent = None @@ -80,8 +80,8 @@ class State: self.job_no += 1 self.sampling_step = 0 self.current_image_sampling_step = 0 - def gen_job_id(self): - return ''.join(random.choices('0123456789abcdefghijklmnopqrstuvwxyz', k=opts.job_id_length)) + def get_job_timestamp(self): + return datetime.datetime.now().strftime("%Y%m%d%H%M%S") state = State() @@ -160,7 +160,6 @@ options_templates.update(options_section(('saving-to-dirs', "Saving to a directo "grid_save_to_dirs": OptionInfo(False, "Save grids to subdirectory"), "directories_filename_pattern": OptionInfo("", "Directory name pattern"), "directories_max_prompt_words": OptionInfo(8, "Max prompt words", gr.Slider, {"minimum": 1, "maximum": 20, "step": 1}), - "job_id_length": OptionInfo(5, "Length of job id", gr.Slider, {"minimum": 5, "maximum": 20, "step": 1}), })) options_templates.update(options_section(('upscaling', "Upscaling"), { diff --git a/webui.py b/webui.py index d0a4e00f..9ea5f5a3 100644 --- a/webui.py +++ b/webui.py @@ -50,7 +50,7 @@ def wrap_gradio_gpu_call(func): shared.state.sampling_step = 0 shared.state.job_count = -1 shared.state.job_no = 0 - shared.state.job_id = shared.state.gen_job_id() + shared.state.job_timestamp = shared.state.get_job_timestamp() shared.state.current_latent = None shared.state.current_image = None shared.state.current_image_sampling_step = 0