Skip to content

Commit c250d2a

Browse files
Merge pull request #4182 from macrosoft/process_one
Process one
2 parents 1b9faaa + de64146 commit c250d2a

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

modules/processing.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,9 @@ def infotext(iteration=0, position_in_batch=0):
501501
if len(prompts) == 0:
502502
break
503503

504+
if p.scripts is not None:
505+
p.scripts.process_one(p, n)
506+
504507
with devices.autocast():
505508
uc = prompt_parser.get_learned_conditioning(shared.sd_model, len(prompts) * [p.negative_prompt], p.steps)
506509
c = prompt_parser.get_multicond_learned_conditioning(shared.sd_model, prompts, p.steps)

modules/scripts.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ def process(self, p, *args):
7373

7474
pass
7575

76+
def process_one(self, p, n, *args):
77+
"""
78+
Same as process(), but called for every iteration
79+
"""
80+
81+
pass
82+
7683
def postprocess(self, p, processed, *args):
7784
"""
7885
This function is called after processing ends for AlwaysVisible scripts.
@@ -296,6 +303,15 @@ def process(self, p):
296303
print(f"Error running process: {script.filename}", file=sys.stderr)
297304
print(traceback.format_exc(), file=sys.stderr)
298305

306+
def process_one(self, p, n):
307+
for script in self.alwayson_scripts:
308+
try:
309+
script_args = p.script_args[script.args_from:script.args_to]
310+
script.process_one(p, n, *script_args)
311+
except Exception:
312+
print(f"Error running process_one: {script.filename}", file=sys.stderr)
313+
print(traceback.format_exc(), file=sys.stderr)
314+
299315
def postprocess(self, p, processed):
300316
for script in self.alwayson_scripts:
301317
try:

0 commit comments

Comments
 (0)