Create save_steps.py
This commit is contained in:
parent
b8dfc54f6c
commit
9d5beae2e0
|
@ -0,0 +1,35 @@
|
|||
import os.path
|
||||
|
||||
import modules.scripts as scripts
|
||||
import gradio as gr
|
||||
|
||||
from modules import sd_samplers, shared
|
||||
from modules.processing import Processed, process_images
|
||||
|
||||
|
||||
class Script(scripts.Script):
|
||||
def title(self):
|
||||
return "Save steps of the sampling process to files"
|
||||
|
||||
def ui(self, is_img2img):
|
||||
path = gr.Textbox(label="Save images to path")
|
||||
return [path]
|
||||
|
||||
def run(self, p, path):
|
||||
index = [0]
|
||||
|
||||
def store_latent(x):
|
||||
image = shared.state.current_image = sd_samplers.sample_to_image(x)
|
||||
image.save(os.path.join(path, f"sample-{index[0]:05}.png"))
|
||||
index[0] += 1
|
||||
fun(x)
|
||||
|
||||
fun = sd_samplers.store_latent
|
||||
sd_samplers.store_latent = store_latent
|
||||
|
||||
try:
|
||||
proc = process_images(p)
|
||||
finally:
|
||||
sd_samplers.store_latent = fun
|
||||
|
||||
return Processed(p, proc.images, p.seed, "")
|
Loading…
Reference in New Issue