Skip to content

Instantly share code, notes, and snippets.

@upbit
Forked from camenduru/run_n_times.py
Last active March 31, 2023 07:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save upbit/67b9753a62cd53e40e45942d08b91540 to your computer and use it in GitHub Desktop.
Save upbit/67b9753a62cd53e40e45942d08b91540 to your computer and use it in GitHub Desktop.
import math
import os
import sys
import traceback
import modules.scripts as scripts
import gradio as gr
from modules.processing import Processed, process_images, fix_seed
class Script(scripts.Script):
def title(self):
return "Run N times - Seed(+1)"
def ui(self, is_img2img):
n = gr.Textbox(label="n", value="3")
no_save_grid = gr.Checkbox(label="Do not save grid", value=True)
return [n, no_save_grid]
def run(self, p, n, no_save_grid):
fix_seed(p)
loop = int(n)
print(f"Prompt matrix will create {loop} images using a total of {p.n_iter} batches.")
original_prompt = p.prompt[0] if type(p.prompt) == list else p.prompt
p.prompt = [original_prompt] * loop
p.prompt_for_display = original_prompt
p.n_iter = math.ceil(loop / p.batch_size)
p.do_not_save_grid = no_save_grid
return process_images(p)
@erasels
Copy link

erasels commented Mar 30, 2023

Great modification of the original, thank you.

@upbit
Copy link
Author

upbit commented Mar 30, 2023

Great modification of the original, thank you.

This script is not very effective. In fact, the batch count is just the Seed+1

@erasels
Copy link

erasels commented Mar 31, 2023

I just needed it because I got out of memory exceptions when I tried to generate bigger images with a batch count of more than 1.
This script fixes that, so I'm happy. Maybe I'm just too much of a noob to see the reason why seed+1 is an issue though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment