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-08-04 13:05:40 -06:00
|
|
|
from modules.ui_extra_networks_checkpoints_user_metadata import CheckpointUserMetadataEditor
|
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-08-03 13:46:57 -06:00
|
|
|
def create_item(self, name, index=None, enable_filter=True):
|
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,
|
2023-08-13 00:32:54 -06:00
|
|
|
"shorthash": checkpoint.shorthash,
|
2023-07-15 23:38:23 -06:00
|
|
|
"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}",
|
2023-07-31 22:08:11 -06:00
|
|
|
"metadata": checkpoint.metadata,
|
2023-07-15 23:38:23 -06:00
|
|
|
"sort_keys": {'default': index, **self.get_sort_keys(checkpoint.filename)},
|
|
|
|
}
|
|
|
|
|
2023-01-28 12:52:27 -07:00
|
|
|
def list_items(self):
|
2023-08-18 23:39:48 -06:00
|
|
|
names = list(sd_models.checkpoints_list)
|
|
|
|
for index, name in enumerate(names):
|
2023-07-15 23:38:23 -06:00
|
|
|
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
|
|
|
|
2023-08-04 13:05:40 -06:00
|
|
|
def create_user_metadata_editor(self, ui, tabname):
|
|
|
|
return CheckpointUserMetadataEditor(ui, tabname, self)
|