Skip to content

Commit 09d9aec

Browse files
authored
add extra noise callbacks
not yet implemented in SDNEXT
1 parent 0212e65 commit 09d9aec

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import time
2+
import inspect
3+
from collections import namedtuple
4+
from typing import Optional, Dict, Any
5+
from fastapi import FastAPI
6+
from gradio import Blocks
7+
import modules.errors as errors
8+
from modules.script_callbacks import ScriptCallback, add_callback, callback_map, timer, report_exception
9+
10+
11+
class ExtraNoiseParams:
12+
def __init__(self, noise, x, xi):
13+
self.noise = noise
14+
"""Random noise generated by the seed"""
15+
self.x = x
16+
"""Latent representation of the image"""
17+
self.xi = xi
18+
"""Noisy latent representation of the image"""
19+
20+
def extra_noise_callback(params: ExtraNoiseParams):
21+
for c in callback_map['callbacks_extra_noise']:
22+
try:
23+
t0 = time.time()
24+
c.callback(params)
25+
timer(t0, c.script, 'extra_noise')
26+
except Exception:
27+
report_exception(c, 'extra_noise_callback')
28+
29+
def on_extra_noise(callback):
30+
"""register a function to be called before adding extra noise in img2img or hires fix;
31+
The callback is called with one argument:
32+
- params: ExtraNoiseParams - contains noise determined by seed and latent representation of image
33+
"""
34+
add_callback(callback_map['callbacks_extra_noise'], callback)

0 commit comments

Comments
 (0)