diff options
author | AUTOMATIC1111 <16777216c@gmail.com> | 2022-10-12 07:35:42 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-12 07:35:42 +0000 |
commit | dc1432e0dd2b826bbf5aee3e87d8270c151e4912 (patch) | |
tree | 276c27910e8ec38a1a054df02c67f73a84cb35df /modules/hypernetworks/ui.py | |
parent | 1d64976dbc5a0f3124567b91fadd5014a9d93c5f (diff) | |
parent | ca5efc316b9431746ff886d259275310f63f95fb (diff) | |
download | stable-diffusion-webui-gfx803-dc1432e0dd2b826bbf5aee3e87d8270c151e4912.tar.gz stable-diffusion-webui-gfx803-dc1432e0dd2b826bbf5aee3e87d8270c151e4912.tar.bz2 stable-diffusion-webui-gfx803-dc1432e0dd2b826bbf5aee3e87d8270c151e4912.zip |
Merge branch 'master' into feature/scale_to
Diffstat (limited to 'modules/hypernetworks/ui.py')
-rw-r--r-- | modules/hypernetworks/ui.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/modules/hypernetworks/ui.py b/modules/hypernetworks/ui.py new file mode 100644 index 00000000..dfa599af --- /dev/null +++ b/modules/hypernetworks/ui.py @@ -0,0 +1,47 @@ +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, devices
+from modules.hypernetworks import hypernetwork
+
+
+def create_hypernetwork(name, enable_sizes):
+ 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, enable_sizes=[int(x) for x in enable_sizes])
+ 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
+
+ assert not shared.cmd_opts.lowvram, 'Training models with lowvram is not possible'
+
+ 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
+ shared.sd_model.cond_stage_model.to(devices.device)
+ shared.sd_model.first_stage_model.to(devices.device)
+ sd_hijack.apply_optimizations()
+
|