From 2c8cbf70a2c7890f8ea5768063c8cebc29063931 Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Tue, 4 Nov 2025 20:50:13 -0500 Subject: [PATCH] inline wildcard obey seed Signed-off-by: Vladimir Mandic --- CHANGELOG.md | 2 ++ modules/styles.py | 14 ++++++++++---- scripts/xyz/xyz_grid_classes.py | 1 - 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 61f8986ec..87f945d13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,9 +44,11 @@ - ui: fix full-screen image viewer buttons with non-standard ui theme - ui: control tab show override section - ui: mobile layout for video tab + - ui: increase init timeout - video: save to subfolder - taesd: warn on long decode times - metadata: keep exif on thumbnail generation + - wildcard: obey seed for reproducible results ## Update for 2025-10-31 diff --git a/modules/styles.py b/modules/styles.py index 9595ff2e7..4ff29b6e1 100644 --- a/modules/styles.py +++ b/modules/styles.py @@ -45,14 +45,20 @@ def apply_styles_to_prompt(prompt, styles): return prompt -def apply_curly_braces_to_prompt(prompt): +def apply_curly_braces_to_prompt(prompt, seed=-1): # woman with {blonde|brunette|red-head|purple highlights} hair curly_braces_matches = re.findall(r'\{(.*?)\}', prompt) for match in curly_braces_matches: + old_state = None + if seed > 0: + old_state = random.getstate() + random.seed(seed) options = match.split('|') if options: choice = random.choice(options).strip() prompt = prompt.replace(f'{{{match}}}', choice, 1) + if old_state is not None: + random.setstate(old_state) return prompt @@ -112,8 +118,8 @@ def apply_wildcards_to_prompt(prompt, all_wildcards, seed=-1, silent=False): return prompt old_state = None if seed > 0 and len(all_wildcards) > 0: - random.seed(seed) old_state = random.getstate() + random.seed(seed) replaced = {} t0 = time.time() for style_wildcards in all_wildcards: @@ -339,7 +345,7 @@ class StyleDatabase: if seeds[i]> 0: random.seed(seeds[i]) prompt = prompts[i] - prompt = apply_curly_braces_to_prompt(prompt) + prompt = apply_curly_braces_to_prompt(prompt, seeds[i]) prompt = apply_styles_to_prompt(prompt, [self.find_style(x).prompt for x in styles]) prompt = apply_wildcards_to_prompt(prompt, [self.find_style(x).wildcards for x in styles], seeds[i]) parsed_positive.append(prompt) @@ -347,7 +353,7 @@ class StyleDatabase: if seeds[i]> 0: random.seed(seeds[i]) prompt = negatives[i] - prompt = apply_curly_braces_to_prompt(prompt) + prompt = apply_curly_braces_to_prompt(prompt, seeds[i]) prompt = apply_styles_to_prompt(prompt, [self.find_style(x).negative_prompt for x in styles]) prompt = apply_wildcards_to_prompt(prompt, [self.find_style(x).wildcards for x in styles], seeds[i]) parsed_negative.append(prompt) diff --git a/scripts/xyz/xyz_grid_classes.py b/scripts/xyz/xyz_grid_classes.py index baab407a1..d2331a731 100644 --- a/scripts/xyz/xyz_grid_classes.py +++ b/scripts/xyz/xyz_grid_classes.py @@ -136,7 +136,6 @@ class SharedSettingsStackHelper(): self.disable_apply_metadata = shared.opts.disable_apply_metadata self.disable_apply_params = shared.opts.disable_apply_params self.sdnq_quant_mode = shared.opts.sdnq_quantize_weights_mode - shared.opts.data["disable_apply_metadata"] = [] shared.opts.data["disable_apply_params"] = ''