ui_extra_networks_hypernets.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import os
  2. from modules import shared, ui_extra_networks
  3. from modules.ui_extra_networks import quote_js
  4. class ExtraNetworksPageHypernetworks(ui_extra_networks.ExtraNetworksPage):
  5. def __init__(self):
  6. super().__init__('Hypernetworks')
  7. def refresh(self):
  8. shared.reload_hypernetworks()
  9. def create_item(self, name, index=None):
  10. full_path = shared.hypernetworks[name]
  11. path, ext = os.path.splitext(full_path)
  12. return {
  13. "name": name,
  14. "filename": full_path,
  15. "preview": self.find_preview(path),
  16. "description": self.find_description(path),
  17. "search_term": self.search_terms_from_path(path),
  18. "prompt": quote_js(f"<hypernet:{name}:") + " + opts.extra_networks_default_multiplier + " + quote_js(">"),
  19. "local_preview": f"{path}.preview.{shared.opts.samples_format}",
  20. "sort_keys": {'default': index, **self.get_sort_keys(path + ext)},
  21. }
  22. def list_items(self):
  23. for index, name in enumerate(shared.hypernetworks):
  24. yield self.create_item(name, index)
  25. def allowed_directories_for_previews(self):
  26. return [shared.cmd_opts.hypernetwork_dir]