From 6d406da4a49fb176ecf3da45ff6dec00c0688198 Mon Sep 17 00:00:00 2001 From: lllyasviel Date: Sat, 12 Aug 2023 07:29:36 -0700 Subject: [PATCH] 1.0.16 (#19) ### 1.0.16 * Implemented "output" folder for saving user results. * Ignored cv2 errors when preview fails. * Mentioned future AMD support in Readme. * Created this log. --- fooocus_version.py | 2 +- modules/cv2win32.py | 18 +++++++++++++----- modules/path.py | 3 +++ modules/util.py | 13 +++++++++++++ readme.md | 6 +++++- update_log.md | 14 ++++++++++++++ webui.py | 9 ++++++++- 7 files changed, 57 insertions(+), 8 deletions(-) create mode 100644 modules/util.py create mode 100644 update_log.md diff --git a/fooocus_version.py b/fooocus_version.py index 7372acca..d7c6d7e0 100644 --- a/fooocus_version.py +++ b/fooocus_version.py @@ -1,2 +1,2 @@ -version = '1.0.15' +version = '1.0.16' diff --git a/modules/cv2win32.py b/modules/cv2win32.py index 5e41dbcf..6a76cfdd 100644 --- a/modules/cv2win32.py +++ b/modules/cv2win32.py @@ -1,5 +1,6 @@ import threading import cv2 +import os buffer = [] @@ -7,9 +8,9 @@ buffer = [] def worker(): global buffer - while True: - cv2.waitKey(50) - try: + try: + while True: + cv2.waitKey(50) if len(buffer) > 0: task = buffer.pop(0) if task is None: @@ -19,11 +20,18 @@ def worker(): cv2.imshow(flag, img) cv2.setWindowTitle(flag, title) cv2.setWindowProperty(flag, cv2.WND_PROP_TOPMOST, 1) - except Exception as e: - print(e) + except Exception as e: + print('Failed to open preview window. You are not using a local device with GUI support.') + print(e) pass +def save_image(path, img): + os.makedirs(os.path.dirname(path), exist_ok=True) + cv2.imwrite(path, img[..., ::-1].copy()) + print(f'Image saved: {path}') + + def show_preview(flag, img, title='preview'): buffer.append((flag, img[..., ::-1].copy(), title)) diff --git a/modules/path.py b/modules/path.py index 2d38161a..d192062f 100644 --- a/modules/path.py +++ b/modules/path.py @@ -2,3 +2,6 @@ import os modelfile_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '../models/checkpoints/')) lorafile_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '../models/loras/')) +temp_outputs_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '../outputs/')) + +os.makedirs(temp_outputs_path, exist_ok=True) diff --git a/modules/util.py b/modules/util.py new file mode 100644 index 00000000..d7bdf427 --- /dev/null +++ b/modules/util.py @@ -0,0 +1,13 @@ +import datetime +import random +import os + + +def generate_temp_filename(folder='./outputs/', extension='png'): + current_time = datetime.datetime.now() + date_string = current_time.strftime("%Y-%m-%d") + time_string = current_time.strftime("%Y-%m-%d_%H-%M-%S") + random_number = random.randint(1000, 9999) + filename = f"{time_string}_{random_number}.{extension}" + result = os.path.join(folder, date_string, filename) + return os.path.abspath(os.path.realpath(result)) diff --git a/readme.md b/readme.md index 364c011a..7d626d10 100644 --- a/readme.md +++ b/readme.md @@ -34,7 +34,7 @@ In the first time you launch the software, it will automatically download models If you already have these files, you can copy them to the above locations to speed up installation. -### Linux and Mac +### Linux/Mac/Windows(AMD GPUs) Coming soon ... @@ -57,3 +57,7 @@ Note that some of these tricks are currently (2023 Aug 11) impossible to reprodu ## Thanks The codebase starts from an odd mixture of [Automatic1111](https://github.com/AUTOMATIC1111/stable-diffusion-webui) and [ComfyUI](https://github.com/comfyanonymous/ComfyUI). (And they both use GPL license.) + +## Update Log + +The log is [here](update_log.md). diff --git a/update_log.md b/update_log.md new file mode 100644 index 00000000..8c65de23 --- /dev/null +++ b/update_log.md @@ -0,0 +1,14 @@ +### 1.0.16 + +* Implemented "output" folder for saving user results. +* Ignored cv2 errors when preview fails. +* Mentioned future AMD support in Readme. +* Created this log. + +### 1.0.15 + +Publicly available. + +### 1.0.0 + +Initial Version. diff --git a/webui.py b/webui.py index 9856a838..4e6336e5 100644 --- a/webui.py +++ b/webui.py @@ -4,7 +4,9 @@ import fooocus_version from modules.sdxl_styles import apply_style, style_keys, aspect_ratios from modules.default_pipeline import process -from modules.cv2win32 import close_all_preview +from modules.cv2win32 import close_all_preview, save_image +from modules.util import generate_temp_filename +from modules.path import temp_outputs_path def generate_clicked(prompt, negative_prompt, style_selction, performance_selction, @@ -34,6 +36,11 @@ def generate_clicked(prompt, negative_prompt, style_selction, performance_selcti for i in range(image_number): imgs = process(p_txt, n_txt, steps, switch, width, height, seed, callback=callback) + + for x in imgs: + local_temp_filename = generate_temp_filename(folder=temp_outputs_path, extension='png') + save_image(local_temp_filename, x) + seed += 1 results += imgs