diff --git a/CHANGELOG.md b/CHANGELOG.md index cebe52296..e6e6f255f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,6 +51,7 @@ - do not set preview samples when using via api - avoid unnecessary resizes in img2img and inpaint - updated `cli/simple-txt2img.py` and `cli/simple-img2img.py` scripts + - save `params.txt` regardless of image save status - update built-in log monitor in ui, thanks @midcoastal ## Update for 2023-12-04 diff --git a/modules/images.py b/modules/images.py index 23708ccd7..2e467105c 100644 --- a/modules/images.py +++ b/modules/images.py @@ -1,4 +1,3 @@ -import datetime import io import re import os @@ -6,13 +5,13 @@ import sys import math import json import uuid +import queue import string import hashlib -import queue +import datetime import threading from pathlib import Path from collections import namedtuple -import pytz import numpy as np import piexif import piexif.helper @@ -393,6 +392,7 @@ class FilenameGenerator: return self.prompt_sanitize(prompt_no_style) def datetime(self, *args): + import pytz time_datetime = datetime.datetime.now() time_format = args[0] if len(args) > 0 and args[0] != "" else self.default_time_format try: @@ -507,6 +507,8 @@ def atomically_save_image(): Image.MAX_IMAGE_PIXELS = None # disable check in Pillow and rely on check below to allow large custom image sizes while True: image, filename, extension, params, exifinfo, filename_txt = save_queue.get() + with open(os.path.join(paths.data_path, "params.txt"), "w", encoding="utf8") as file: + file.write(exifinfo) fn = filename + extension filename = filename.strip() if extension[0] != '.': # add dot if missing @@ -562,8 +564,6 @@ def atomically_save_image(): image.save(fn, format=image_format, quality=shared.opts.jpeg_quality) except Exception as e: shared.log.error(f'Image save failed: file="{fn}" {e}') - with open(os.path.join(paths.data_path, "params.txt"), "w", encoding="utf8") as file: - file.write(exifinfo) if shared.opts.save_log_fn != '' and len(exifinfo) > 0: fn = os.path.join(paths.data_path, shared.opts.save_log_fn) if not fn.endswith('.json'): @@ -575,8 +575,6 @@ def atomically_save_image(): entry = { 'id': idx, 'filename': filename, 'time': datetime.datetime.now().isoformat(), 'info': exifinfo } entries.append(entry) shared.writefile(entries, fn, mode='w') - with open(os.path.join(paths.data_path, "params.txt"), "w", encoding="utf8") as file: - file.write(exifinfo) save_queue.task_done() diff --git a/modules/ui_extra_networks.py b/modules/ui_extra_networks.py index f424402e2..f4a0945a0 100644 --- a/modules/ui_extra_networks.py +++ b/modules/ui_extra_networks.py @@ -797,21 +797,25 @@ def create_ui(container, button_parent, tabname, skip_indexing = False): prompt = '' params = generation_parameters_copypaste.parse_generation_parameters(prompt) fn = os.path.join(shared.opts.styles_dir, os.path.splitext(name)[0] + '.json') + prompt = params.get('Prompt', '') item = { - "type": 'Style', "name": name, - "title": name, - "filename": fn, - "search_term": None, - "preview": None, "description": '', - "prompt": params.get('Prompt', ''), + "prompt": prompt, "negative": params.get('Negative prompt', ''), "extra": '', - "local_preview": None, + # "type": 'Style', + # "title": name, + # "filename": fn, + # "search_term": None, + # "preview": None, + # "local_preview": None, } shared.writefile(item, fn, silent=True) - shared.log.debug(f"Extra network quick save style: item={item['name']} filename='{fn}'") + if len(prompt) > 0: + shared.log.debug(f"Extra network quick save style: item={name} filename='{fn}'") + else: + shared.log.warning(f"Extra network quick save model: item={name} filename='{fn}' prompt is empty") def ui_sort_cards(msg): shared.log.debug(f'Extra networks: {msg}')