From b36208234fffd18e8ff6d33b6a34dbba22d496fd Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Thu, 4 Jan 2024 08:58:54 -0500 Subject: [PATCH] fix ui dummy comp --- CHANGELOG.md | 6 ++-- cli/image-exif.py | 43 +++++++++++++++++++++----- extensions-builtin/sd-webui-controlnet | 2 +- modules/lora | 2 +- modules/ui.py | 2 +- modules/ui_img2img.py | 3 +- 6 files changed, 44 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 95ca53780..fad23d0cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,8 +33,10 @@ And it also includes fixes for all reported issues so far - enable vae tiling - add autodetect optimial value set tile size to 0 to use autodetected value - - **cli**: sdapi.py allow manual api invoke - example: `python cli/sdapi.py /sdapi/v1/sd-models` + - **cli**: + - `sdapi.py` allow manual api invoke + example: `python cli/sdapi.py /sdapi/v1/sd-models` + - `image-exif.py` improve metadata parsing - **memory**: add ram usage monitoring in addition to gpu memory usage monitoring - **vae**: enable taesd batch decode enable/disable with settings -> diffusers > vae slicing diff --git a/cli/image-exif.py b/cli/image-exif.py index df77e6d30..43ea8df18 100755 --- a/cli/image-exif.py +++ b/cli/image-exif.py @@ -4,12 +4,9 @@ import os import io import re import sys -import json from PIL import Image, ExifTags, TiffImagePlugin, PngImagePlugin from rich import print # pylint: disable=redefined-builtin -# warnings.filterwarnings("ignore", category=UserWarning) - class Exif: # pylint: disable=single-string-used-for-slots __slots__ = ('__dict__') # pylint: disable=superfluous-parens @@ -69,6 +66,36 @@ class Exif: # pylint: disable=single-string-used-for-slots pass return None + def parse(self): + re_param_code = r'\s*([\w ]+):\s*("(?:\\"[^,]|\\"|\\|[^\"])+"|[^,]*)(?:,|$)' + re_param = re.compile(re_param_code) + x = self.exif.pop('parameters', None) or self.exif.pop('UserComment', None) + res = {} + if x is None: + return res + remaining = x.replace('\n', ' ').strip() + if len(remaining) == 0: + return res + remaining = x[7:] if x.startswith('Prompt: ') else x + remaining = x[11:] if x.startswith('parameters: ') else x + if 'Steps: ' in remaining and 'Negative prompt: ' not in remaining: + remaining = remaining.replace('Steps: ', 'Negative prompt: Steps: ') + prompt, remaining = remaining.strip().split('Negative prompt: ', maxsplit=1) if 'Negative prompt: ' in remaining else (remaining, '') + res["Prompt"] = prompt.strip() + negative, remaining = remaining.strip().split('Steps: ', maxsplit=1) if 'Steps: ' in remaining else (remaining, None) + res["Negative prompt"] = negative.strip() + if remaining is None: + return res + remaining = f'Steps: {remaining}' + for k, v in re_param.findall(remaining.strip()): + if v.isdigit(): + res[k] = float(v) if '.' in v else int(v) + else: + res[k] = v + from types import SimpleNamespace + ns = SimpleNamespace(**res) + return ns + def get_bytes(self): ifd = TiffImagePlugin.ImageFileDirectory_v2() exif_stream = io.BytesIO() @@ -87,13 +114,13 @@ def read_exif(filename: str): from pi_heif import register_heif_opener register_heif_opener() try: - img = Image.open(filename) - exif = Exif(img) - print('image:', filename, 'format:', img.format, 'metadata:', json.dumps(vars(exif.exif)['_data'], indent=2)) + image = Image.open(filename) + exif = Exif(image) + print('image:', filename, 'format:', image) + print('exif:', vars(exif.exif)['_data']) + print('info:', exif.parse()) except Exception as e: print('metadata error reading:', filename, e) - # exif.exif['Software'] = 'This is a Test' - # img.save('input-scored.jpg', exif=exif.bytes()) if __name__ == '__main__': diff --git a/extensions-builtin/sd-webui-controlnet b/extensions-builtin/sd-webui-controlnet index 8bd8057cc..e3fe75268 160000 --- a/extensions-builtin/sd-webui-controlnet +++ b/extensions-builtin/sd-webui-controlnet @@ -1 +1 @@ -Subproject commit 8bd8057cca51fb0d951a9b8be42bc9873b6087da +Subproject commit e3fe75268ef38d85ef35a3cf5b7e894a285b1b18 diff --git a/modules/lora b/modules/lora index 1a36f9dc6..4f93bf10f 160000 --- a/modules/lora +++ b/modules/lora @@ -1 +1 @@ -Subproject commit 1a36f9dc65fb3be8baa9dcbde832048cc5644efa +Subproject commit 4f93bf10f0f3b84afb7f1670c48eda3dedb4c1d8 diff --git a/modules/ui.py b/modules/ui.py index 4b4b40f9d..8780b40bb 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -228,7 +228,7 @@ def create_ui(startup_timer = None): def run_settings(*args): changed = [] for key, value, comp in zip(opts.data_labels.keys(), args, components): - if comp == dummy_component: + if comp == dummy_component or value=='dummy': continue if not opts.same_type(value, opts.data_labels[key].default): log.error(f'Setting bad value: {key}={value} expecting={type(opts.data_labels[key].default).__name__}') diff --git a/modules/ui_img2img.py b/modules/ui_img2img.py index ebe3392bd..0b073d075 100644 --- a/modules/ui_img2img.py +++ b/modules/ui_img2img.py @@ -144,7 +144,8 @@ def create_ui(): cfg_scale, clip_skip, image_cfg_scale, diffusers_guidance_rescale, sag_scale, full_quality, restore_faces, tiling, hdr_clamp, hdr_boundary, hdr_threshold, hdr_center, hdr_channel_shift, hdr_full_shift, hdr_maximize, hdr_max_center, hdr_max_boundry = ui_sections.create_advanced_inputs('img2img') - with FormGroup(elem_id="inpaint_controls", visible=False) as inpaint_controls: + # with FormGroup(elem_id="inpaint_controls", visible=False) as inpaint_controls: + with gr.Accordion(open=True, label="Mask", elem_classes=["small-accordion"], elem_id="img2img_mask_group") as inpaint_controls: with FormRow(): mask_blur = gr.Slider(label='Mask blur', minimum=0, maximum=64, step=1, value=4, elem_id="img2img_mask_blur") mask_alpha = gr.Slider(label="Mask transparency", visible=False, elem_id="img2img_mask_alpha")