aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modules/extras.py2
-rw-r--r--modules/processing.py2
-rw-r--r--modules/scripts.py19
-rw-r--r--modules/sd_hijack.py4
-rw-r--r--scripts/custom_code.py6
-rw-r--r--scripts/loopback.py6
6 files changed, 32 insertions, 7 deletions
diff --git a/modules/extras.py b/modules/extras.py
index 3d9d9f7a..cc8fed1b 100644
--- a/modules/extras.py
+++ b/modules/extras.py
@@ -60,7 +60,7 @@ def run_extras(image, image_folder, gfpgan_visibility, codeformer_visibility, co
if codeformer_visibility < 1.0:
res = Image.blend(image, res, codeformer_visibility)
- info += f"CodeFormer w: {round(codeformer_weight, 2)}, CodeFormer visibility:{round(codeformer_visibility)}\n"
+ info += f"CodeFormer w: {round(codeformer_weight, 2)}, CodeFormer visibility:{round(codeformer_visibility, 2)}\n"
image = res
if upscaling_resize != 1.0:
diff --git a/modules/processing.py b/modules/processing.py
index 6a99d383..a60dec24 100644
--- a/modules/processing.py
+++ b/modules/processing.py
@@ -339,6 +339,8 @@ def process_images(p: StableDiffusionProcessing) -> Processed:
state.nextjob()
+ p.color_corrections = None
+
unwanted_grid_because_of_img_count = len(output_images) < 2 and opts.grid_only_if_multiple
if (opts.return_grid or opts.grid_save) and not p.do_not_save_grid and not unwanted_grid_because_of_img_count:
grid = images.image_grid(output_images, p.batch_size)
diff --git a/modules/scripts.py b/modules/scripts.py
index 9cc5a185..0e0b949b 100644
--- a/modules/scripts.py
+++ b/modules/scripts.py
@@ -13,18 +13,37 @@ class Script:
args_from = None
args_to = None
+ # The title of the script. This is what will be displayed in the dropdown menu.
def title(self):
raise NotImplementedError()
+ # How the script is displayed in the UI. See https://gradio.app/docs/#components
+ # for the different UI components you can use and how to create them.
+ # Most UI components can return a value, such as a boolean for a checkbox.
+ # The returned values are passed to the run method as parameters.
def ui(self, is_img2img):
pass
+ # Determines when the script should be shown in the dropdown menu via the
+ # returned value. As an example:
+ # is_img2img is True if the current tab is img2img, and False if it is txt2img.
+ # Thus, return is_img2img to only show the script on the img2img tab.
def show(self, is_img2img):
return True
+ # This is where the additional processing is implemented. The parameters include
+ # self, the model object "p" (a StableDiffusionProcessing class, see
+ # processing.py), and the parameters returned by the ui method.
+ # Custom functions can be defined here, and additional libraries can be imported
+ # to be used in processing. The return value should be a Processed object, which is
+ # what is returned by the process_images method.
def run(self, *args):
raise NotImplementedError()
+ # The description method is currently unused.
+ # To add a description that appears when hovering over the title, amend the "titles"
+ # dict in script.js to include the script title (returned by title) as a key, and
+ # your description as the value.
def describe(self):
return ""
diff --git a/modules/sd_hijack.py b/modules/sd_hijack.py
index 65414518..c4450ce4 100644
--- a/modules/sd_hijack.py
+++ b/modules/sd_hijack.py
@@ -50,7 +50,7 @@ def split_cross_attention_forward(self, x, context=None, mask=None):
q_in = self.to_q(x)
context = default(context, x)
- k_in = self.to_k(context)
+ k_in = self.to_k(context) * self.scale
v_in = self.to_v(context)
del context, x
@@ -85,7 +85,7 @@ def split_cross_attention_forward(self, x, context=None, mask=None):
slice_size = q.shape[1] // steps if (q.shape[1] % steps) == 0 else q.shape[1]
for i in range(0, q.shape[1], slice_size):
end = i + slice_size
- s1 = einsum('b i d, b j d -> b i j', q[:, i:end], k) * self.scale
+ s1 = einsum('b i d, b j d -> b i j', q[:, i:end], k)
s2 = s1.softmax(dim=-1, dtype=q.dtype)
del s1
diff --git a/scripts/custom_code.py b/scripts/custom_code.py
index 5694f2dd..a9b10c09 100644
--- a/scripts/custom_code.py
+++ b/scripts/custom_code.py
@@ -4,8 +4,8 @@ import gradio as gr
from modules.processing import Processed
from modules.shared import opts, cmd_opts, state
-
class Script(scripts.Script):
+
def title(self):
return "Custom code"
@@ -18,6 +18,7 @@ class Script(scripts.Script):
return [code]
+
def run(self, p, code):
assert cmd_opts.allow_code, '--allow-code option must be enabled'
@@ -37,4 +38,5 @@ class Script(scripts.Script):
exec(compiled, module.__dict__)
return Processed(p, *display_result_data)
-
+
+ \ No newline at end of file
diff --git a/scripts/loopback.py b/scripts/loopback.py
index 8aca61f3..e90b58d4 100644
--- a/scripts/loopback.py
+++ b/scripts/loopback.py
@@ -40,8 +40,7 @@ class Script(scripts.Script):
all_images = []
state.job_count = loops * batch_count
- if opts.img2img_color_correction:
- p.color_corrections = [processing.setup_color_correction(p.init_images[0])]
+ initial_color_corrections = [processing.setup_color_correction(p.init_images[0])]
for n in range(batch_count):
history = []
@@ -51,6 +50,9 @@ class Script(scripts.Script):
p.batch_size = 1
p.do_not_save_grid = True
+ if opts.img2img_color_correction:
+ p.color_corrections = initial_color_corrections
+
state.job = f"Iteration {i + 1}/{loops}, batch {n + 1}/{batch_count}"
processed = processing.process_images(p)