Merge pull request #776 from MoonRide303/seed-range-refactor

Refactored handling max random seed
This commit is contained in:
MoonRide303 2023-10-24 18:09:42 +02:00 committed by GitHub
commit 2f58ac2334
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 8 deletions

View File

@ -23,6 +23,7 @@ def worker():
import fcbh.model_management import fcbh.model_management
import fooocus_extras.preprocessors as preprocessors import fooocus_extras.preprocessors as preprocessors
import modules.inpaint_worker as inpaint_worker import modules.inpaint_worker as inpaint_worker
import modules.constants as constants
import modules.advanced_parameters as advanced_parameters import modules.advanced_parameters as advanced_parameters
import fooocus_extras.ip_adapter as ip_adapter import fooocus_extras.ip_adapter as ip_adapter
@ -225,7 +226,7 @@ def worker():
progressbar(3, 'Processing prompts ...') progressbar(3, 'Processing prompts ...')
tasks = [] tasks = []
for i in range(image_number): 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_rng = random.Random(task_seed) # may bind to inpaint noise in the future
task_prompt = apply_wildcards(prompt, task_rng) task_prompt = apply_wildcards(prompt, task_rng)

3
modules/constants.py Normal file
View File

@ -0,0 +1,3 @@
# as in k-diffusion (sampling.py)
MIN_SEED = 0
MAX_SEED = 2**63 - 1

View File

@ -9,6 +9,7 @@ import modules.path
import fooocus_version import fooocus_version
import modules.html import modules.html
import modules.async_worker as worker import modules.async_worker as worker
import modules.constants as constants
import modules.flags as flags import modules.flags as flags
import modules.gradio_hijack as grh import modules.gradio_hijack as grh
import modules.advanced_parameters as advanced_parameters 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.private_logger import get_current_html_path
from modules.ui_gradio_extensions import reload_javascript 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): def generate_clicked(*args):
execution_start_time = time.perf_counter() execution_start_time = time.perf_counter()
@ -204,15 +201,15 @@ with shared.gradio_root:
def refresh_seed(r, seed_string): def refresh_seed(r, seed_string):
if r: if r:
return random.randint(MIN_SEED, MAX_SEED) return random.randint(constants.MIN_SEED, constants.MAX_SEED)
else: else:
try: try:
seed_value = int(seed_string) seed_value = int(seed_string)
if MIN_SEED <= seed_value <= MAX_SEED: if constants.MIN_SEED <= seed_value <= constants.MAX_SEED:
return seed_value return seed_value
except ValueError: except ValueError:
pass 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) seed_random.change(random_checked, inputs=[seed_random], outputs=[image_seed], queue=False)