refactor detailer

Signed-off-by: Vladimir Mandic <mandic00@live.com>
This commit is contained in:
Vladimir Mandic
2025-01-07 10:12:47 -05:00
parent 19d56d3342
commit 5593ea78a9
21 changed files with 142 additions and 82 deletions
+5 -2
View File
@@ -1,4 +1,4 @@
from scripts.xyz_grid_shared import apply_field, apply_task_args, apply_setting, apply_prompt, apply_order, apply_sampler, apply_hr_sampler_name, confirm_samplers, apply_checkpoint, apply_refiner, apply_unet, apply_dict, apply_clip_skip, apply_vae, list_lora, apply_lora, apply_lora_strength, apply_te, apply_styles, apply_upscaler, apply_context, apply_detailer, apply_override, apply_processing, apply_options, apply_seed, format_value_add_label, format_value, format_value_join_list, do_nothing, format_nothing, str_permutations # pylint: disable=no-name-in-module, unused-import
from scripts.xyz_grid_shared import apply_field, apply_task_args, apply_setting, apply_prompt_primary, apply_prompt_refine, apply_prompt_detailer, apply_prompt_all, apply_order, apply_sampler, apply_hr_sampler_name, confirm_samplers, apply_checkpoint, apply_refiner, apply_unet, apply_dict, apply_clip_skip, apply_vae, list_lora, apply_lora, apply_lora_strength, apply_te, apply_styles, apply_upscaler, apply_context, apply_detailer, apply_override, apply_processing, apply_options, apply_seed, format_value_add_label, format_value, format_value_join_list, do_nothing, format_nothing, str_permutations # pylint: disable=no-name-in-module, unused-import
from modules import shared, shared_items, sd_samplers, ipadapter, sd_models, sd_vae, sd_unet
@@ -93,7 +93,10 @@ axis_options = [
AxisOption("[Model] Refiner", str, apply_refiner, cost=0.8, fmt=format_value_add_label, choices=lambda: ['None'] + sorted(sd_models.checkpoints_list)),
AxisOption("[Model] Text encoder", str, apply_te, cost=0.7, choices=shared_items.sd_te_items),
AxisOption("[Model] Dictionary", str, apply_dict, fmt=format_value_add_label, cost=0.9, choices=lambda: ['None'] + list(sd_models.checkpoints_list)),
AxisOption("[Prompt] Search & replace", str, apply_prompt, fmt=format_value_add_label),
AxisOption("[Prompt] Search & replace", str, apply_prompt_primary, fmt=format_value_add_label),
AxisOption("[Prompt] Search & replace refine", str, apply_prompt_refine, fmt=format_value_add_label),
AxisOption("[Prompt] Search & replace detailer", str, apply_prompt_detailer, fmt=format_value_add_label),
AxisOption("[Prompt] Search & replace all", str, apply_prompt_all, fmt=format_value_add_label),
AxisOption("[Prompt] Prompt order", str_permutations, apply_order, fmt=format_value_join_list),
AxisOption("[Prompt] Prompt parser", str, apply_setting("prompt_attention"), choices=lambda: ["native", "compel", "xhinker", "a1111", "fixed"]),
AxisOption("[Network] LoRA", str, apply_lora, cost=0.5, choices=list_lora),
+3 -3
View File
@@ -286,8 +286,8 @@ class Script(scripts.Script):
total_steps += p.hr_second_pass_steps * total_jobs
else:
total_steps *= 2
if p.detailer:
total_steps += shared.opts.detailer_steps * total_jobs
if p.detailer_enabled:
total_steps += p.detailer_steps * total_jobs
total_steps *= p.n_iter
total_jobs *= p.n_iter
@@ -432,7 +432,7 @@ class Script(scripts.Script):
def process_images(self, p, *args): # pylint: disable=W0221, W0613
if xyz_results_cache is not None and len(xyz_results_cache.images) > 0:
p.restore_faces = False
p.detailer = False
p.detailer_enabled = False
p.color_corrections = None
# p.scripts = None
return xyz_results_cache
+27 -8
View File
@@ -62,18 +62,37 @@ def apply_seed(p, x, xs):
shared.log.debug(f'XYZ grid apply seed: {x}')
def apply_prompt(p, x, xs):
def apply_prompt(positive, negative, p, x, xs):
for s in xs:
if s in p.prompt:
shared.log.debug(f'XYZ grid apply prompt: "{s}"="{x}"')
p.prompt = p.prompt.replace(s, x)
if s in p.negative_prompt:
shared.log.debug(f'XYZ grid apply negative: "{s}"="{x}"')
p.negative_prompt = p.negative_prompt.replace(s, x)
shared.log.debug(f'XYZ grid apply prompt: fields={positive}/{negative} "{s}"="{x}"')
orig_positive = getattr(p, positive)
orig_negative = getattr(p, negative)
if s in orig_positive:
setattr(p, positive, orig_positive.replace(s, x))
if s in orig_negative:
setattr(p, negative, orig_negative.replace(s, x))
def apply_prompt_primary(p, x, xs):
apply_prompt('prompt', 'negative_prompt', p, x, xs)
p.all_prompts = None
p.all_negative_prompts = None
def apply_prompt_refine(p, x, xs):
apply_prompt('refiner_prompt', 'refiner_negative', p, x, xs)
def apply_prompt_detailer(p, x, xs):
apply_prompt('detailer_prompt', 'detailer_negative', p, x, xs)
def apply_prompt_all(p, x, xs):
apply_prompt('prompt', 'negative_prompt', p, x, xs)
apply_prompt('refiner_prompt', 'refiner_negative', p, x, xs)
apply_prompt('detailer_prompt', 'detailer_negative', p, x, xs)
def apply_order(p, x, xs):
token_order = []
for token in x:
@@ -251,7 +270,7 @@ def apply_detailer(p, opt, x):
p.detailer_model = 'GFPGAN'
else:
is_active = opt in ('true', 'yes', 'y', '1')
p.detailer = is_active
p.detailer_enabled = is_active
shared.log.debug(f'XYZ grid apply face-restore: "{x}"')