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