aboutsummaryrefslogtreecommitdiff
path: root/modules/hypernetworks/ui.py
diff options
context:
space:
mode:
authoryfszzx <yfszzx@gmail.com>2022-10-12 20:48:03 +0800
committeryfszzx <yfszzx@gmail.com>2022-10-12 20:48:03 +0800
commit511ca57e37483aac0cf260c89838ad2948509101 (patch)
tree8d6fb6ccd0cfc470460c68cf8d054bfc98dbdb34 /modules/hypernetworks/ui.py
parente05573e1adc1cde1e3bd7eb651a1ab27c446b3d5 (diff)
parenta36dea9596c8880609401ce4fa7ab83cf70a9b2b (diff)
Merge branch 'master' of https://github.com/yfszzx/stable-diffusion-webui-plus
Diffstat (limited to 'modules/hypernetworks/ui.py')
-rw-r--r--modules/hypernetworks/ui.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/modules/hypernetworks/ui.py b/modules/hypernetworks/ui.py
new file mode 100644
index 00000000..e7540f41
--- /dev/null
+++ b/modules/hypernetworks/ui.py
@@ -0,0 +1,43 @@
+import html
+import os
+
+import gradio as gr
+
+import modules.textual_inversion.textual_inversion
+import modules.textual_inversion.preprocess
+from modules import sd_hijack, shared
+from modules.hypernetworks import hypernetwork
+
+
+def create_hypernetwork(name):
+ fn = os.path.join(shared.cmd_opts.hypernetwork_dir, f"{name}.pt")
+ assert not os.path.exists(fn), f"file {fn} already exists"
+
+ hypernet = modules.hypernetworks.hypernetwork.Hypernetwork(name=name)
+ hypernet.save(fn)
+
+ shared.reload_hypernetworks()
+
+ return gr.Dropdown.update(choices=sorted([x for x in shared.hypernetworks.keys()])), f"Created: {fn}", ""
+
+
+def train_hypernetwork(*args):
+
+ initial_hypernetwork = shared.loaded_hypernetwork
+
+ try:
+ sd_hijack.undo_optimizations()
+
+ hypernetwork, filename = modules.hypernetworks.hypernetwork.train_hypernetwork(*args)
+
+ res = f"""
+Training {'interrupted' if shared.state.interrupted else 'finished'} at {hypernetwork.step} steps.
+Hypernetwork saved to {html.escape(filename)}
+"""
+ return res, ""
+ except Exception:
+ raise
+ finally:
+ shared.loaded_hypernetwork = initial_hypernetwork
+ sd_hijack.apply_optimizations()
+