From 3c855bd3319228148ec7d8666dd679da9007dcdd Mon Sep 17 00:00:00 2001 From: Manuel Schmid Date: Sun, 14 Jan 2024 20:19:49 +0100 Subject: [PATCH] feat: use consistent file name in gradio returns and uses filepaths instead of numpy image by saving to temp dir uses double the temp dir file storage on disk as it saves to temp dir and gradio temp dir when displaying the image, but reuses logged output image --- modules/async_worker.py | 9 +++++---- modules/private_logger.py | 15 +++++++++------ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/modules/async_worker.py b/modules/async_worker.py index b2af6712..0668834a 100644 --- a/modules/async_worker.py +++ b/modules/async_worker.py @@ -511,8 +511,8 @@ def worker(): if direct_return: d = [('Upscale (Fast)', '2x')] - log(uov_input_image, d) - yield_result(async_task, uov_input_image, do_not_show_finished_images=True) + uov_input_image_path = log(uov_input_image, d) + yield_result(async_task, uov_input_image_path, do_not_show_finished_images=True) return tiled = True @@ -774,6 +774,7 @@ def worker(): if inpaint_worker.current_task is not None: imgs = [inpaint_worker.current_task.post_process(x) for x in imgs] + img_paths = [] for x in imgs: d = [ ('Prompt', task['log_positive_prompt']), @@ -799,9 +800,9 @@ def worker(): if n != 'None': d.append((f'LoRA {li + 1}', f'{n} : {w}')) d.append(('Version', 'v' + fooocus_version.version)) - log(x, d) + img_paths.append(log(x, d)) - yield_result(async_task, imgs, do_not_show_finished_images=len(tasks) == 1) + yield_result(async_task, img_paths, do_not_show_finished_images=len(tasks) == 1) except ldm_patched.modules.model_management.InterruptProcessingException as e: if shared.last_stop == 'skip': print('User skipped') diff --git a/modules/private_logger.py b/modules/private_logger.py index 968bd4f5..d5f352fa 100644 --- a/modules/private_logger.py +++ b/modules/private_logger.py @@ -3,6 +3,7 @@ import args_manager import modules.config import json import urllib.parse +import tempfile from PIL import Image from modules.util import generate_temp_filename @@ -18,13 +19,15 @@ def get_current_html_path(): return html_name -def log(img, dic): - if args_manager.args.disable_image_log: - return - - date_string, local_temp_filename, only_name = generate_temp_filename(folder=modules.config.path_outputs, extension='png') +def log(img, dic) -> str: + path_outputs = tempfile.gettempdir() if args_manager.args.disable_image_log else modules.config.path_outputs + date_string, local_temp_filename, only_name = generate_temp_filename(folder=path_outputs, extension='png') os.makedirs(os.path.dirname(local_temp_filename), exist_ok=True) Image.fromarray(img).save(local_temp_filename) + + if args_manager.args.disable_image_log: + return local_temp_filename + html_name = os.path.join(os.path.dirname(local_temp_filename), 'log.html') css_styles = ( @@ -105,4 +108,4 @@ def log(img, dic): log_cache[html_name] = middle_part - return + return local_temp_filename