2023-01-28 12:52:27 -07:00
|
|
|
import html
|
|
|
|
import os
|
|
|
|
|
|
|
|
from modules import shared, ui_extra_networks, sd_models
|
2023-07-16 00:25:32 -06:00
|
|
|
from modules.ui_extra_networks import quote_js
|
2023-01-28 12:52:27 -07:00
|
|
|
|
|
|
|
|
|
|
|
class ExtraNetworksPageCheckpoints(ui_extra_networks.ExtraNetworksPage):
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__('Checkpoints')
|
|
|
|
|
|
|
|
def refresh(self):
|
|
|
|
shared.refresh_checkpoints()
|
|
|
|
|
2023-07-15 23:38:23 -06:00
|
|
|
def create_item(self, name, index=None):
|
2023-07-16 00:49:22 -06:00
|
|
|
checkpoint: sd_models.CheckpointInfo = sd_models.checkpoint_aliases.get(name)
|
2023-07-15 23:38:23 -06:00
|
|
|
path, ext = os.path.splitext(checkpoint.filename)
|
|
|
|
return {
|
|
|
|
"name": checkpoint.name_for_extra,
|
|
|
|
"filename": checkpoint.filename,
|
|
|
|
"preview": self.find_preview(path),
|
|
|
|
"description": self.find_description(path),
|
|
|
|
"search_term": self.search_terms_from_path(checkpoint.filename) + " " + (checkpoint.sha256 or ""),
|
2023-07-16 00:25:32 -06:00
|
|
|
"onclick": '"' + html.escape(f"""return selectCheckpoint({quote_js(name)})""") + '"',
|
2023-07-15 23:38:23 -06:00
|
|
|
"local_preview": f"{path}.{shared.opts.samples_format}",
|
|
|
|
"sort_keys": {'default': index, **self.get_sort_keys(checkpoint.filename)},
|
|
|
|
}
|
|
|
|
|
2023-01-28 12:52:27 -07:00
|
|
|
def list_items(self):
|
2023-07-15 23:38:23 -06:00
|
|
|
for index, name in enumerate(sd_models.checkpoints_list):
|
|
|
|
yield self.create_item(name, index)
|
2023-01-28 12:52:27 -07:00
|
|
|
|
|
|
|
def allowed_directories_for_previews(self):
|
2023-01-29 00:32:53 -07:00
|
|
|
return [v for v in [shared.cmd_opts.ckpt_dir, sd_models.model_path] if v is not None]
|
2023-01-28 12:52:27 -07:00
|
|
|
|