ui_extra_networks_checkpoints.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import html
  2. import os
  3. from modules import shared, ui_extra_networks, sd_models
  4. from modules.ui_extra_networks import quote_js
  5. class ExtraNetworksPageCheckpoints(ui_extra_networks.ExtraNetworksPage):
  6. def __init__(self):
  7. super().__init__('Checkpoints')
  8. def refresh(self):
  9. shared.refresh_checkpoints()
  10. def create_item(self, name, index=None):
  11. checkpoint: sd_models.CheckpointInfo = sd_models.checkpoint_aliases.get(name)
  12. path, ext = os.path.splitext(checkpoint.filename)
  13. return {
  14. "name": checkpoint.name_for_extra,
  15. "filename": checkpoint.filename,
  16. "preview": self.find_preview(path),
  17. "description": self.find_description(path),
  18. "search_term": self.search_terms_from_path(checkpoint.filename) + " " + (checkpoint.sha256 or ""),
  19. "onclick": '"' + html.escape(f"""return selectCheckpoint({quote_js(name)})""") + '"',
  20. "local_preview": f"{path}.{shared.opts.samples_format}",
  21. "sort_keys": {'default': index, **self.get_sort_keys(checkpoint.filename)},
  22. }
  23. def list_items(self):
  24. for index, name in enumerate(sd_models.checkpoints_list):
  25. yield self.create_item(name, index)
  26. def allowed_directories_for_previews(self):
  27. return [v for v in [shared.cmd_opts.ckpt_dir, sd_models.model_path] if v is not None]