From 2c24e09dfc431ef7617134a807bf741f0b0c9fa3 Mon Sep 17 00:00:00 2001 From: Sakura-Luna <53183413+Sakura-Luna@users.noreply.github.com> Date: Thu, 20 Apr 2023 14:53:04 +0800 Subject: [PATCH 1/9] Fix gallery not being refreshed correctly --- modules/txt2img.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/txt2img.py b/modules/txt2img.py index 16841d0f2..6ebca656a 100644 --- a/modules/txt2img.py +++ b/modules/txt2img.py @@ -7,6 +7,7 @@ from modules.shared import opts, cmd_opts import modules.shared as shared import modules.processing as processing from modules.ui import plaintext_to_html +from time import time def txt2img(id_task: str, prompt: str, negative_prompt: str, prompt_styles, steps: int, sampler_index: int, restore_faces: bool, tiling: bool, n_iter: int, batch_size: int, cfg_scale: float, seed: int, subseed: int, subseed_strength: float, seed_resize_from_h: int, seed_resize_from_w: int, seed_enable_extras: bool, height: int, width: int, enable_hr: bool, denoising_strength: float, hr_scale: float, hr_upscaler: str, hr_second_pass_steps: int, hr_resize_x: int, hr_resize_y: int, override_settings_texts, *args): @@ -63,6 +64,9 @@ def txt2img(id_task: str, prompt: str, negative_prompt: str, prompt_styles, step if opts.samples_log_stdout: print(generation_info_js) + for img in processed.images: + img.already_saved_as += f'?{int(time())}' + if opts.do_not_show_images: processed.images = [] From 988dd02632bf38e64bc0cf394ece2a5f7a64e15b Mon Sep 17 00:00:00 2001 From: Sakura-Luna <53183413+Sakura-Luna@users.noreply.github.com> Date: Thu, 20 Apr 2023 15:08:31 +0800 Subject: [PATCH 2/9] Add img2img refreshed correctly --- modules/img2img.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/img2img.py b/modules/img2img.py index 953ac5d2d..6da974e45 100644 --- a/modules/img2img.py +++ b/modules/img2img.py @@ -15,6 +15,7 @@ import modules.processing as processing from modules.ui import plaintext_to_html import modules.images as images import modules.scripts +from time import time def process_batch(p, input_dir, output_dir, inpaint_mask_dir, args): @@ -179,6 +180,9 @@ def img2img(id_task: str, mode: int, prompt: str, negative_prompt: str, prompt_s if opts.samples_log_stdout: print(generation_info_js) + for img in processed.images: + img.already_saved_as += f'?{int(time())}' + if opts.do_not_show_images: processed.images = [] From eff00413ae76e01b9a24b13dee6a0dda98f643f2 Mon Sep 17 00:00:00 2001 From: Sakura-Luna <53183413+Sakura-Luna@users.noreply.github.com> Date: Thu, 20 Apr 2023 21:23:56 +0800 Subject: [PATCH 3/9] Refresh bug fix --- modules/img2img.py | 3 ++- modules/txt2img.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/img2img.py b/modules/img2img.py index 6da974e45..fea51667b 100644 --- a/modules/img2img.py +++ b/modules/img2img.py @@ -181,7 +181,8 @@ def img2img(id_task: str, mode: int, prompt: str, negative_prompt: str, prompt_s print(generation_info_js) for img in processed.images: - img.already_saved_as += f'?{int(time())}' + if hasattr(img, 'already_saved_as'): + img.already_saved_as += f'?{int(time())}' if opts.do_not_show_images: processed.images = [] diff --git a/modules/txt2img.py b/modules/txt2img.py index 6ebca656a..57278bdc3 100644 --- a/modules/txt2img.py +++ b/modules/txt2img.py @@ -65,7 +65,8 @@ def txt2img(id_task: str, prompt: str, negative_prompt: str, prompt_styles, step print(generation_info_js) for img in processed.images: - img.already_saved_as += f'?{int(time())}' + if hasattr(img, 'already_saved_as'): + img.already_saved_as += f'?{int(time())}' if opts.do_not_show_images: processed.images = [] From 29e13867bff5a00388e5eb1dd04c16c6e8f33e4f Mon Sep 17 00:00:00 2001 From: Sakura-Luna <53183413+Sakura-Luna@users.noreply.github.com> Date: Thu, 4 May 2023 14:08:20 +0800 Subject: [PATCH 4/9] Revert "Refresh bug fix" This reverts commit eff00413ae76e01b9a24b13dee6a0dda98f643f2. --- modules/img2img.py | 3 +-- modules/txt2img.py | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/modules/img2img.py b/modules/img2img.py index fea51667b..6da974e45 100644 --- a/modules/img2img.py +++ b/modules/img2img.py @@ -181,8 +181,7 @@ def img2img(id_task: str, mode: int, prompt: str, negative_prompt: str, prompt_s print(generation_info_js) for img in processed.images: - if hasattr(img, 'already_saved_as'): - img.already_saved_as += f'?{int(time())}' + img.already_saved_as += f'?{int(time())}' if opts.do_not_show_images: processed.images = [] diff --git a/modules/txt2img.py b/modules/txt2img.py index 57278bdc3..6ebca656a 100644 --- a/modules/txt2img.py +++ b/modules/txt2img.py @@ -65,8 +65,7 @@ def txt2img(id_task: str, prompt: str, negative_prompt: str, prompt_styles, step print(generation_info_js) for img in processed.images: - if hasattr(img, 'already_saved_as'): - img.already_saved_as += f'?{int(time())}' + img.already_saved_as += f'?{int(time())}' if opts.do_not_show_images: processed.images = [] From 35e5916af9ccf1661c6b262b768d4b241ab9eee7 Mon Sep 17 00:00:00 2001 From: Sakura-Luna <53183413+Sakura-Luna@users.noreply.github.com> Date: Thu, 4 May 2023 14:08:21 +0800 Subject: [PATCH 5/9] Revert "Add img2img refreshed correctly" This reverts commit 988dd02632bf38e64bc0cf394ece2a5f7a64e15b. --- modules/img2img.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/modules/img2img.py b/modules/img2img.py index 6da974e45..953ac5d2d 100644 --- a/modules/img2img.py +++ b/modules/img2img.py @@ -15,7 +15,6 @@ import modules.processing as processing from modules.ui import plaintext_to_html import modules.images as images import modules.scripts -from time import time def process_batch(p, input_dir, output_dir, inpaint_mask_dir, args): @@ -180,9 +179,6 @@ def img2img(id_task: str, mode: int, prompt: str, negative_prompt: str, prompt_s if opts.samples_log_stdout: print(generation_info_js) - for img in processed.images: - img.already_saved_as += f'?{int(time())}' - if opts.do_not_show_images: processed.images = [] From 5c66fedb641841958020c0f8693fc69dee7a96a1 Mon Sep 17 00:00:00 2001 From: Sakura-Luna <53183413+Sakura-Luna@users.noreply.github.com> Date: Thu, 4 May 2023 14:08:22 +0800 Subject: [PATCH 6/9] Revert "Fix gallery not being refreshed correctly" This reverts commit 2c24e09dfc431ef7617134a807bf741f0b0c9fa3. --- modules/txt2img.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/modules/txt2img.py b/modules/txt2img.py index 6ebca656a..16841d0f2 100644 --- a/modules/txt2img.py +++ b/modules/txt2img.py @@ -7,7 +7,6 @@ from modules.shared import opts, cmd_opts import modules.shared as shared import modules.processing as processing from modules.ui import plaintext_to_html -from time import time def txt2img(id_task: str, prompt: str, negative_prompt: str, prompt_styles, steps: int, sampler_index: int, restore_faces: bool, tiling: bool, n_iter: int, batch_size: int, cfg_scale: float, seed: int, subseed: int, subseed_strength: float, seed_resize_from_h: int, seed_resize_from_w: int, seed_enable_extras: bool, height: int, width: int, enable_hr: bool, denoising_strength: float, hr_scale: float, hr_upscaler: str, hr_second_pass_steps: int, hr_resize_x: int, hr_resize_y: int, override_settings_texts, *args): @@ -64,9 +63,6 @@ def txt2img(id_task: str, prompt: str, negative_prompt: str, prompt_styles, step if opts.samples_log_stdout: print(generation_info_js) - for img in processed.images: - img.already_saved_as += f'?{int(time())}' - if opts.do_not_show_images: processed.images = [] From 91a15dca80f44e32461f0ab7219de632781a2622 Mon Sep 17 00:00:00 2001 From: Sakura-Luna <53183413+Sakura-Luna@users.noreply.github.com> Date: Thu, 4 May 2023 14:38:15 +0800 Subject: [PATCH 7/9] Use a new way to solve webpage refresh --- modules/ui_tempdir.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/ui_tempdir.py b/modules/ui_tempdir.py index 21945235e..82b9c4e48 100644 --- a/modules/ui_tempdir.py +++ b/modules/ui_tempdir.py @@ -2,6 +2,7 @@ import os import tempfile from collections import namedtuple from pathlib import Path +from time import time import gradio as gr @@ -34,7 +35,7 @@ def check_tmp_file(gradio, filename): def save_pil_to_file(pil_image, dir=None): already_saved_as = getattr(pil_image, 'already_saved_as', None) if already_saved_as and os.path.isfile(already_saved_as): - register_tmp_file(shared.demo, already_saved_as) + register_tmp_file(shared.demo, f'{already_saved_as}?{int(time())}') file_obj = Savedfile(already_saved_as) return file_obj From 8bc4a3a2a8d6ad9b439cb90d52600cc50e9b4f42 Mon Sep 17 00:00:00 2001 From: Sakura-Luna <53183413+Sakura-Luna@users.noreply.github.com> Date: Thu, 4 May 2023 15:55:57 +0800 Subject: [PATCH 8/9] Refresh fix --- modules/ui_tempdir.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/ui_tempdir.py b/modules/ui_tempdir.py index 82b9c4e48..42a85d3b8 100644 --- a/modules/ui_tempdir.py +++ b/modules/ui_tempdir.py @@ -35,7 +35,8 @@ def check_tmp_file(gradio, filename): def save_pil_to_file(pil_image, dir=None): already_saved_as = getattr(pil_image, 'already_saved_as', None) if already_saved_as and os.path.isfile(already_saved_as): - register_tmp_file(shared.demo, f'{already_saved_as}?{int(time())}') + already_saved_as += f'?{int(time())}' + register_tmp_file(shared.demo, already_saved_as) file_obj = Savedfile(already_saved_as) return file_obj From a3cdf9aaf85399d6ddfb5bc3245d8f154802fe58 Mon Sep 17 00:00:00 2001 From: Sakura-Luna <53183413+Sakura-Luna@users.noreply.github.com> Date: Fri, 5 May 2023 15:51:01 +0800 Subject: [PATCH 9/9] Reopen image fix --- modules/generation_parameters_copypaste.py | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/generation_parameters_copypaste.py b/modules/generation_parameters_copypaste.py index 6df76858f..ae855627d 100644 --- a/modules/generation_parameters_copypaste.py +++ b/modules/generation_parameters_copypaste.py @@ -59,6 +59,7 @@ def image_from_url_text(filedata): is_in_right_dir = ui_tempdir.check_tmp_file(shared.demo, filename) assert is_in_right_dir, 'trying to open image file outside of allowed directories' + filename = filename.rsplit('?', 1)[0] return Image.open(filename) if type(filedata) == list: