2023-01-28 19:52:27 +00:00
|
|
|
import html
|
|
|
|
import os
|
|
|
|
|
|
|
|
from modules import shared, ui_extra_networks, sd_models
|
2023-07-16 06:25:32 +00:00
|
|
|
from modules.ui_extra_networks import quote_js
|
2023-08-04 19:05:40 +00:00
|
|
|
from modules.ui_extra_networks_checkpoints_user_metadata import CheckpointUserMetadataEditor
|
2023-01-28 19:52:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ExtraNetworksPageCheckpoints(ui_extra_networks.ExtraNetworksPage):
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__('Checkpoints')
|
|
|
|
|
|
|
|
def refresh(self):
|
|
|
|
shared.refresh_checkpoints()
|
|
|
|
|
2023-08-03 19:46:57 +00:00
|
|
|
def create_item(self, name, index=None, enable_filter=True):
|
2023-07-16 06:49:22 +00:00
|
|
|
checkpoint: sd_models.CheckpointInfo = sd_models.checkpoint_aliases.get(name)
|
2023-09-09 08:28:06 +00:00
|
|
|
if checkpoint is None:
|
|
|
|
return
|
|
|
|
|
2023-07-16 05:38:23 +00:00
|
|
|
path, ext = os.path.splitext(checkpoint.filename)
|
|
|
|
return {
|
|
|
|
"name": checkpoint.name_for_extra,
|
|
|
|
"filename": checkpoint.filename,
|
2023-08-13 06:32:54 +00:00
|
|
|
"shorthash": checkpoint.shorthash,
|
2023-07-16 05:38:23 +00: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 06:25:32 +00:00
|
|
|
"onclick": '"' + html.escape(f"""return selectCheckpoint({quote_js(name)})""") + '"',
|
2023-07-16 05:38:23 +00:00
|
|
|
"local_preview": f"{path}.{shared.opts.samples_format}",
|
2023-08-01 04:08:11 +00:00
|
|
|
"metadata": checkpoint.metadata,
|
2023-07-16 05:38:23 +00:00
|
|
|
"sort_keys": {'default': index, **self.get_sort_keys(checkpoint.filename)},
|
|
|
|
}
|
|
|
|
|
2023-01-28 19:52:27 +00:00
|
|
|
def list_items(self):
|
2023-09-09 07:56:19 +00:00
|
|
|
names = list(sd_models.checkpoints_list)
|
|
|
|
for index, name in enumerate(names):
|
2023-09-09 08:28:06 +00:00
|
|
|
item = self.create_item(name, index)
|
|
|
|
if item is not None:
|
|
|
|
yield item
|
2023-01-28 19:52:27 +00:00
|
|
|
|
|
|
|
def allowed_directories_for_previews(self):
|
2023-01-29 07:32:53 +00:00
|
|
|
return [v for v in [shared.cmd_opts.ckpt_dir, sd_models.model_path] if v is not None]
|
2023-01-28 19:52:27 +00:00
|
|
|
|
2023-08-04 19:05:40 +00:00
|
|
|
def create_user_metadata_editor(self, ui, tabname):
|
|
|
|
return CheckpointUserMetadataEditor(ui, tabname, self)
|