xyz improvements

Signed-off-by: Vladimir Mandic <mandic00@live.com>
This commit is contained in:
Vladimir Mandic
2024-11-25 08:01:02 -05:00
parent e4038feff1
commit d76365e227
3 changed files with 22 additions and 24 deletions
+2
View File
@@ -135,6 +135,7 @@ class ExtraNetworksPage:
return text.replace('~tabname', tabname)
def create_xyz_grid(self):
"""
xyz_grid = [x for x in scripts.scripts_data if x.script_class.__module__ == "xyz_grid.py"][0].module
def add_prompt(p, opt, x):
@@ -150,6 +151,7 @@ class ExtraNetworksPage:
opt = xyz_grid.AxisOption(f"[Network] {self.title}", str, add_prompt, choices=lambda: [x["name"] for x in self.items])
if opt not in xyz_grid.axis_options:
xyz_grid.axis_options.append(opt)
"""
def link_preview(self, filename):
quoted_filename = urllib.parse.quote(filename.replace('\\', '/'))
+2 -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_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, 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
@@ -97,7 +97,7 @@ axis_options = [
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),
AxisOption("[Network] LoRA strength", float, apply_setting('extra_networks_default_multiplier')),
AxisOption("[Network] LoRA strength", float, apply_lora_strength),
AxisOption("[Network] Styles", str, apply_styles, choices=lambda: [s.name for s in shared.prompt_styles.styles.values()]),
AxisOption("[Param] Width", int, apply_field("width")),
AxisOption("[Param] Height", int, apply_field("height")),
+18 -22
View File
@@ -63,28 +63,15 @@ def apply_seed(p, x, xs):
def apply_prompt(p, x, xs):
if not hasattr(p, 'orig_prompt'):
p.orig_prompt = p.prompt
p.orig_negative = p.negative_prompt
if xs[0] not in p.orig_prompt and xs[0] not in p.orig_negative:
shared.log.warning(f'XYZ grid: prompt S/R string="{xs[0]}" not found')
else:
p.prompt = p.orig_prompt.replace(xs[0], x)
p.negative_prompt = p.orig_negative.replace(xs[0], x)
p.all_prompts = None
p.all_negative_prompts = None
"""
if p.all_prompts is not None:
for i in range(len(p.all_prompts)):
for j in range(len(xs)):
p.all_prompts[i] = p.all_prompts[i].replace(xs[j], x)
p.negative_prompt = p.negative_prompt.replace(xs[0], x)
if p.all_negative_prompts is not None:
for i in range(len(p.all_negative_prompts)):
for j in range(len(xs)):
p.all_negative_prompts[i] = p.all_negative_prompts[i].replace(xs[j], x)
"""
shared.log.debug(f'XYZ grid apply prompt: "{xs[0]}"="{x}"')
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)
p.all_prompts = None
p.all_negative_prompts = None
def apply_order(p, x, xs):
@@ -220,6 +207,15 @@ def apply_lora(p, x, xs):
shared.log.debug(f'XYZ grid apply LoRA: "{x}"')
def apply_lora_strength(p, x, xs):
shared.log.debug(f'XYZ grid apply LoRA strength: "{x}"')
p.prompt = p.prompt.replace(':1.0>', '>')
p.prompt = p.prompt.replace(f':{shared.opts.extra_networks_default_multiplier}>', '>')
p.all_prompts = None
p.all_negative_prompts = None
shared.opts.data['extra_networks_default_multiplier'] = x
def apply_te(p, x, xs):
shared.opts.data["sd_text_encoder"] = x
sd_models.reload_text_encoder()