Skip to content

Commit

Permalink
infotext updates: add option to disregard certain infotext fields, ad…
Browse files Browse the repository at this point in the history
…d option to not include VAE in infotext, add explanation to infotext settings page, move some options to infotext settings page
  • Loading branch information
AUTOMATIC1111 committed Dec 2, 2023
1 parent f0f100e commit b58d061
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 12 deletions.
13 changes: 9 additions & 4 deletions modules/generation_parameters_copypaste.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import annotations
import base64
import io
import json
Expand All @@ -15,9 +16,6 @@
re_hypernet_hash = re.compile("\(([0-9a-f]+)\)$")
type_of_gr_update = type(gr.update())

paste_fields = {}
registered_param_bindings = []


class ParamBinding:
def __init__(self, paste_button, tabname, source_text_component=None, source_image_component=None, source_tabname=None, override_settings_component=None, paste_field_names=None):
Expand All @@ -30,6 +28,10 @@ def __init__(self, paste_button, tabname, source_text_component=None, source_ima
self.paste_field_names = paste_field_names or []


paste_fields: dict[str, dict] = {}
registered_param_bindings: list[ParamBinding] = []


def reset():
paste_fields.clear()
registered_param_bindings.clear()
Expand Down Expand Up @@ -113,7 +115,6 @@ def register_paste_params_button(binding: ParamBinding):


def connect_paste_params_buttons():
binding: ParamBinding
for binding in registered_param_bindings:
destination_image_component = paste_fields[binding.tabname]["init_img"]
fields = paste_fields[binding.tabname]["fields"]
Expand Down Expand Up @@ -313,6 +314,9 @@ def parse_generation_parameters(x: str):
if "VAE Decoder" not in res:
res["VAE Decoder"] = "Full"

skip = set(shared.opts.infotext_skip_pasting)
res = {k: v for k, v in res.items() if k not in skip}

return res


Expand Down Expand Up @@ -443,3 +447,4 @@ def paste_settings(params):
outputs=[],
show_progress=False,
)

4 changes: 2 additions & 2 deletions modules/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,8 +679,8 @@ def create_infotext(p, all_prompts, all_seeds, all_subseeds, comments=None, iter
"Size": f"{p.width}x{p.height}",
"Model hash": p.sd_model_hash if opts.add_model_hash_to_info else None,
"Model": p.sd_model_name if opts.add_model_name_to_info else None,
"VAE hash": p.sd_vae_hash if opts.add_model_hash_to_info else None,
"VAE": p.sd_vae_name if opts.add_model_name_to_info else None,
"VAE hash": p.sd_vae_hash if opts.add_vae_hash_to_info else None,
"VAE": p.sd_vae_name if opts.add_vae_name_to_info else None,
"Variation seed": (None if p.subseed_strength == 0 else (p.all_subseeds[0] if use_main_prompt else all_subseeds[index])),
"Variation seed strength": (None if p.subseed_strength == 0 else p.subseed_strength),
"Seed resize from": (None if p.seed_resize_from_w <= 0 or p.seed_resize_from_h <= 0 else f"{p.seed_resize_from_w}x{p.seed_resize_from_h}"),
Expand Down
16 changes: 16 additions & 0 deletions modules/shared_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,22 @@ def reload_hypernetworks():
shared.hypernetworks = hypernetwork.list_hypernetworks(cmd_opts.hypernetwork_dir)


def get_infotext_names():
from modules import generation_parameters_copypaste, shared
res = {}

for info in shared.opts.data_labels.values():
if info.infotext:
res[info.infotext] = 1

for tab_data in generation_parameters_copypaste.paste_fields.values():
for _, name in tab_data.get("fields") or []:
if isinstance(name, str):
res[name] = 1

return list(res)


ui_reorder_categories_builtin_items = [
"prompt",
"image",
Expand Down
20 changes: 14 additions & 6 deletions modules/shared_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@
"grid_text_inactive_color": OptionInfo("#999999", "Inactive text color for image grids", ui_components.FormColorPicker, {}),
"grid_background_color": OptionInfo("#ffffff", "Background color for image grids", ui_components.FormColorPicker, {}),

"enable_pnginfo": OptionInfo(True, "Save text information about generation parameters as chunks to png files"),
"save_txt": OptionInfo(False, "Create a text file next to every image with generation parameters."),
"save_images_before_face_restoration": OptionInfo(False, "Save a copy of image before doing face restoration."),
"save_images_before_highres_fix": OptionInfo(False, "Save a copy of image before applying highres fix."),
"save_images_before_color_correction": OptionInfo(False, "Save a copy of image before applying color correction to img2img results"),
Expand Down Expand Up @@ -288,11 +286,21 @@


options_templates.update(options_section(('infotext', "Infotext", "ui"), {
"add_model_hash_to_info": OptionInfo(True, "Add model hash to generation information"),
"add_model_name_to_info": OptionInfo(True, "Add model name to generation information"),
"add_user_name_to_info": OptionInfo(False, "Add user name to generation information when authenticated"),
"add_version_to_infotext": OptionInfo(True, "Add program version to generation information"),
"infotext_explanation": OptionHTML("""
Infotext is what this software calls the text that contains generation parameters and can be used to generate the same picture again.
It is displayed in UI below the image. To use infotext, paste it into the prompt and click the ↙️ paste button.
"""),
"enable_pnginfo": OptionInfo(True, "Write infotext to metadata of the generated image"),
"save_txt": OptionInfo(False, "Create a text file with infotext next to every generated image"),

"add_model_name_to_info": OptionInfo(True, "Add model name to infotext"),
"add_model_hash_to_info": OptionInfo(True, "Add model hash to infotext"),
"add_vae_name_to_info": OptionInfo(True, "Add VAE name to infotext"),
"add_vae_hash_to_info": OptionInfo(True, "Add VAE hash to infotext"),
"add_user_name_to_info": OptionInfo(False, "Add user name to infotext when authenticated"),
"add_version_to_infotext": OptionInfo(True, "Add program version to infotext"),
"disable_weights_auto_swap": OptionInfo(True, "Disregard checkpoint information from pasted infotext").info("when reading generation parameters from text into UI"),
"infotext_skip_pasting": OptionInfo([], "Disregard fields from pasted infotext", ui_components.DropdownMulti, lambda: {"choices": shared_items.get_infotext_names()}),
"infotext_styles": OptionInfo("Apply if any", "Infer styles from prompts of pasted infotext", gr.Radio, {"choices": ["Ignore", "Apply", "Discard", "Apply if any"]}).info("when reading generation parameters from text into UI)").html("""<ul style='margin-left: 1.5em'>
<li>Ignore: keep prompt and styles dropdown as it is.</li>
<li>Apply: remove style text from prompt, always replace styles dropdown value with found styles (even if none are found).</li>
Expand Down

0 comments on commit b58d061

Please sign in to comment.