Path: blob/master/modules/hypernetworks/ui.py
3068 views
import html12import gradio as gr3import modules.hypernetworks.hypernetwork4from modules import devices, sd_hijack, shared56not_available = ["hardswish", "multiheadattention"]7keys = [x for x in modules.hypernetworks.hypernetwork.HypernetworkModule.activation_dict if x not in not_available]8910def create_hypernetwork(name, enable_sizes, overwrite_old, layer_structure=None, activation_func=None, weight_init=None, add_layer_norm=False, use_dropout=False, dropout_structure=None):11filename = modules.hypernetworks.hypernetwork.create_hypernetwork(name, enable_sizes, overwrite_old, layer_structure, activation_func, weight_init, add_layer_norm, use_dropout, dropout_structure)1213return gr.Dropdown.update(choices=sorted(shared.hypernetworks)), f"Created: {filename}", ""141516def train_hypernetwork(*args):17shared.loaded_hypernetworks = []1819assert not shared.cmd_opts.lowvram, 'Training models with lowvram is not possible'2021try:22sd_hijack.undo_optimizations()2324hypernetwork, filename = modules.hypernetworks.hypernetwork.train_hypernetwork(*args)2526res = f"""27Training {'interrupted' if shared.state.interrupted else 'finished'} at {hypernetwork.step} steps.28Hypernetwork saved to {html.escape(filename)}29"""30return res, ""31except Exception:32raise33finally:34shared.sd_model.cond_stage_model.to(devices.device)35shared.sd_model.first_stage_model.to(devices.device)36sd_hijack.apply_optimizations()37383940