extra_networks_hypernet.py 1.1 KB

12345678910111213141516171819202122232425262728
  1. from modules import extra_networks, shared
  2. from modules.hypernetworks import hypernetwork
  3. class ExtraNetworkHypernet(extra_networks.ExtraNetwork):
  4. def __init__(self):
  5. super().__init__('hypernet')
  6. def activate(self, p, params_list):
  7. additional = shared.opts.sd_hypernetwork
  8. if additional != "None" and additional in shared.hypernetworks and not any(x for x in params_list if x.items[0] == additional):
  9. hypernet_prompt_text = f"<hypernet:{additional}:{shared.opts.extra_networks_default_multiplier}>"
  10. p.all_prompts = [f"{prompt}{hypernet_prompt_text}" for prompt in p.all_prompts]
  11. params_list.append(extra_networks.ExtraNetworkParams(items=[additional, shared.opts.extra_networks_default_multiplier]))
  12. names = []
  13. multipliers = []
  14. for params in params_list:
  15. assert params.items
  16. names.append(params.items[0])
  17. multipliers.append(float(params.items[1]) if len(params.items) > 1 else 1.0)
  18. hypernetwork.load_hypernetworks(names, multipliers)
  19. def deactivate(self, p):
  20. pass