From 769795407907d601186b5298c72b452648bd7741 Mon Sep 17 00:00:00 2001 From: Smirking Kitsune <36494751+SmirkingKitsune@users.noreply.github.com> Date: Mon, 15 Jul 2024 16:48:52 -0600 Subject: [PATCH] Trailing Commas Fix Fixes trailing commas, and minor organization of how the final interrogation is processed and handled. --- scripts/sd_tag_batch.py | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/scripts/sd_tag_batch.py b/scripts/sd_tag_batch.py index f02d6e7..0733452 100644 --- a/scripts/sd_tag_batch.py +++ b/scripts/sd_tag_batch.py @@ -501,9 +501,7 @@ class Script(scripts.ScriptBuiltinUI): # Filter prevents overexaggeration of tags due to interrogation models having similar results if not exaggeration_mode: - interrogation = f"{self.clean_string(interrogation)}, " - else: - interrogation = f"{interrogation}, " + interrogation = self.clean_string(interrogation) # Remove duplicate prompt content from interrogator prompt if use_positive_filter: @@ -514,6 +512,16 @@ class Script(scripts.ScriptBuiltinUI): # Remove custom prompt content from interrogator prompt if use_custom_filter: interrogation = self.filter_words(interrogation, custom_filter) + + # Experimental tool for removing puncuations, but commas and a variety of emojis + if no_puncuation_mode: + interrogation = self.remove_punctuation(interrogation) + + # This will weight the interrogation, and also ensure that trailing commas to the interrogation are correctly placed. + if prompt_weight_mode: + interrogation = f"({interrogation.rstrip(', ')}:{prompt_weight}), " + else: + interrogation = f"({interrogation.rstrip(', ')}), " # Experimental reverse mode prep if not reverse_mode: @@ -521,16 +529,6 @@ class Script(scripts.ScriptBuiltinUI): else: prompt = p.negative_prompt - # This will weight the interrogation - if prompt_weight_mode: - interrogation = f"({interrogation}:{prompt_weight}), " - else: - interrogation = f"{interrogation}, " - - # Experimental tool for removing puncuations, but commas and a variety of emojis - if no_puncuation_mode: - interrogation = f"{self.remove_punctuation(interrogation)}, " - # This will construct the prompt if prompt == "": prompt = interrogation @@ -546,7 +544,7 @@ class Script(scripts.ScriptBuiltinUI): Note: p.prompt, p.all_prompts[0], and prompts[0] To get A1111 to record the updated prompt, p.all_prompts needs to be updated. But, in process_batch to update the stable diffusion prompt, prompts[0] needs to be updated. - prompts[0] are already parsed for network syntax, + prompts[0] are already parsed for extra network syntax, """ p.prompt = prompt for i in range(len(p.all_prompts)):