From 523aa190db1cd23aa7d9c52b0d5404d46bfac898 Mon Sep 17 00:00:00 2001 From: MoonRide303 Date: Tue, 24 Oct 2023 12:15:43 +0200 Subject: [PATCH] Refactored handling max random seed --- modules/async_worker.py | 3 ++- modules/constants.py | 3 +++ webui.py | 11 ++++------- 3 files changed, 9 insertions(+), 8 deletions(-) create mode 100644 modules/constants.py diff --git a/modules/async_worker.py b/modules/async_worker.py index 48ec32c..820bdc3 100644 --- a/modules/async_worker.py +++ b/modules/async_worker.py @@ -23,6 +23,7 @@ def worker(): import fcbh.model_management import fooocus_extras.preprocessors as preprocessors import modules.inpaint_worker as inpaint_worker + import modules.constants as constants import modules.advanced_parameters as advanced_parameters import fooocus_extras.ip_adapter as ip_adapter @@ -225,7 +226,7 @@ def worker(): progressbar(3, 'Processing prompts ...') tasks = [] for i in range(image_number): - task_seed = seed + i + task_seed = (seed + i) % (constants.MAX_SEED + 1) # randint is inclusive, % is not task_rng = random.Random(task_seed) # may bind to inpaint noise in the future task_prompt = apply_wildcards(prompt, task_rng) diff --git a/modules/constants.py b/modules/constants.py new file mode 100644 index 0000000..47c268f --- /dev/null +++ b/modules/constants.py @@ -0,0 +1,3 @@ +# as in k-diffusion (sampling.py) +MIN_SEED = 0 +MAX_SEED = 2**63 - 1 diff --git a/webui.py b/webui.py index e0702d8..7bd082f 100644 --- a/webui.py +++ b/webui.py @@ -9,6 +9,7 @@ import modules.path import fooocus_version import modules.html import modules.async_worker as worker +import modules.constants as constants import modules.flags as flags import modules.gradio_hijack as grh import modules.advanced_parameters as advanced_parameters @@ -18,10 +19,6 @@ from modules.sdxl_styles import legal_style_names from modules.private_logger import get_current_html_path from modules.ui_gradio_extensions import reload_javascript -# as in k-diffusion (sampling.py) -MIN_SEED = 0 -MAX_SEED = 2**63 - 1024 # for image number increasing safety - def generate_clicked(*args): execution_start_time = time.perf_counter() @@ -204,15 +201,15 @@ with shared.gradio_root: def refresh_seed(r, seed_string): if r: - return random.randint(MIN_SEED, MAX_SEED) + return random.randint(constants.MIN_SEED, constants.MAX_SEED) else: try: seed_value = int(seed_string) - if MIN_SEED <= seed_value <= MAX_SEED: + if constants.MIN_SEED <= seed_value <= constants.MAX_SEED: return seed_value except ValueError: pass - return random.randint(MIN_SEED, MAX_SEED) + return random.randint(constants.MIN_SEED, constants.MAX_SEED) seed_random.change(random_checked, inputs=[seed_random], outputs=[image_seed], queue=False)