aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMilly <milly.ca@gmail.com>2022-10-09 15:56:36 +0000
committerAUTOMATIC1111 <16777216c@gmail.com>2022-10-12 07:40:10 +0000
commit2d006ce16cd95d587533656c3ac4991495e96f23 (patch)
treebcb074556255d3be2d5a24ebc50d8f07691dd618
parent4aeacaefbf2ffec6a5b118a3f18af5e7ddf02303 (diff)
downloadstable-diffusion-webui-gfx803-2d006ce16cd95d587533656c3ac4991495e96f23.tar.gz
stable-diffusion-webui-gfx803-2d006ce16cd95d587533656c3ac4991495e96f23.tar.bz2
stable-diffusion-webui-gfx803-2d006ce16cd95d587533656c3ac4991495e96f23.zip
xy_grid: Find hypernetwork by closest name
-rw-r--r--modules/hypernetworks/hypernetwork.py11
-rw-r--r--scripts/xy_grid.py6
2 files changed, 16 insertions, 1 deletions
diff --git a/modules/hypernetworks/hypernetwork.py b/modules/hypernetworks/hypernetwork.py
index 470659df..8f2192e2 100644
--- a/modules/hypernetworks/hypernetwork.py
+++ b/modules/hypernetworks/hypernetwork.py
@@ -120,6 +120,17 @@ def load_hypernetwork(filename):
shared.loaded_hypernetwork = None
+def find_closest_hypernetwork_name(search: str):
+ if not search:
+ return None
+ search = search.lower()
+ applicable = [name for name in shared.hypernetworks if search in name.lower()]
+ if not applicable:
+ return None
+ applicable = sorted(applicable, key=lambda name: len(name))
+ return applicable[0]
+
+
def apply_hypernetwork(hypernetwork, context, layer=None):
hypernetwork_layers = (hypernetwork.layers if hypernetwork is not None else {}).get(context.shape[2], None)
diff --git a/scripts/xy_grid.py b/scripts/xy_grid.py
index ef431105..6f4217ec 100644
--- a/scripts/xy_grid.py
+++ b/scripts/xy_grid.py
@@ -84,7 +84,11 @@ def apply_checkpoint(p, x, xs):
def apply_hypernetwork(p, x, xs):
- hypernetwork.load_hypernetwork(x)
+ if x.lower() in ["", "none"]:
+ name = None
+ else:
+ name = hypernetwork.find_closest_hypernetwork_name(x)
+ hypernetwork.load_hypernetwork(name)
def apply_clip_skip(p, x, xs):