From db1a49f78971867f7c06ddd9cf69aeb68a86a641 Mon Sep 17 00:00:00 2001 From: lvmin Date: Thu, 17 Aug 2023 15:17:32 -0700 Subject: [PATCH] random seed restoring --- modules/async_worker.py | 9 +++++++-- webui.py | 20 +++++++++++++++++--- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/modules/async_worker.py b/modules/async_worker.py index 0ce88849..28b8d15d 100644 --- a/modules/async_worker.py +++ b/modules/async_worker.py @@ -54,8 +54,13 @@ def worker(): results = [] seed = image_seed - if not isinstance(seed, int) or seed < 0 or seed > 1024*1024*1024: - seed = random.randint(1, 1024*1024*1024) + max_seed = int(1024*1024*1024) + + if not isinstance(seed, int): + seed = random.randint(1, max_seed) + if seed < 0: + seed = - seed + seed = seed % max_seed all_steps = steps * image_number diff --git a/webui.py b/webui.py index 0bc3662d..a2a5c09c 100644 --- a/webui.py +++ b/webui.py @@ -1,5 +1,5 @@ import gradio as gr -import sys +import random import time import shared import argparse @@ -59,8 +59,21 @@ with shared.gradio_root: aspect_ratios_selction = gr.Radio(label='Aspect Ratios (width × height)', choices=list(aspect_ratios.keys()), value='1152×896') image_number = gr.Slider(label='Image Number', minimum=1, maximum=32, step=1, value=2) - image_seed = gr.Number(label='Random Seed', value=-1, precision=0) negative_prompt = gr.Textbox(label='Negative Prompt', show_label=True, placeholder="Type prompt here.") + seed_random = gr.Checkbox(label='Random', value=True) + image_seed = gr.Number(label='Seed', value=0, precision=0, visible=False) + + def random_checked(r): + return gr.update(visible=not r) + + def refresh_seed(r, s): + if r: + return random.randint(1, 1024*1024*1024) + else: + return s + + seed_random.change(random_checked, inputs=[seed_random], outputs=[image_seed]) + with gr.Tab(label='Style'): style_selction = gr.Radio(show_label=False, container=True, choices=style_keys, value='cinematic-default') @@ -97,7 +110,8 @@ with shared.gradio_root: performance_selction, aspect_ratios_selction, image_number, image_seed, sharpness ] ctrls += [base_model, refiner_model] + lora_ctrls - run_button.click(fn=generate_clicked, inputs=ctrls, outputs=[run_button, progress_html, progress_window, gallery]) + run_button.click(fn=refresh_seed, inputs=[seed_random, image_seed], outputs=image_seed)\ + .then(fn=generate_clicked, inputs=ctrls, outputs=[run_button, progress_html, progress_window, gallery]) parser = argparse.ArgumentParser()