Skip to content

Commit

Permalink
xyz improvements
Browse files Browse the repository at this point in the history
Signed-off-by: Vladimir Mandic <[email protected]>
  • Loading branch information
vladmandic committed Nov 25, 2024
1 parent e4038fe commit d76365e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 24 deletions.
2 changes: 2 additions & 0 deletions modules/ui_extra_networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ def patch(self, text: str, tabname: str):
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):
Expand All @@ -150,6 +151,7 @@ def add_prompt(p, opt, x):
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('\\', '/'))
Expand Down
4 changes: 2 additions & 2 deletions scripts/xyz_grid_classes.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -97,7 +97,7 @@ def __exit__(self, exc_type, exc_value, tb):
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")),
Expand Down
40 changes: 18 additions & 22 deletions scripts/xyz_grid_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit d76365e

Please sign in to comment.