2023-01-28 19:52:27 +00:00
|
|
|
import html
|
|
|
|
import json
|
|
|
|
import os
|
|
|
|
|
|
|
|
from modules import shared, ui_extra_networks, sd_models
|
|
|
|
|
|
|
|
|
|
|
|
class ExtraNetworksPageCheckpoints(ui_extra_networks.ExtraNetworksPage):
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__('Checkpoints')
|
|
|
|
|
|
|
|
def refresh(self):
|
|
|
|
shared.refresh_checkpoints()
|
|
|
|
|
|
|
|
def list_items(self):
|
2023-01-29 22:41:23 +00:00
|
|
|
checkpoint: sd_models.CheckpointInfo
|
2023-06-02 04:08:45 +00:00
|
|
|
for index, (name, checkpoint) in enumerate(sd_models.checkpoints_list.items()):
|
2023-01-28 19:52:27 +00:00
|
|
|
path, ext = os.path.splitext(checkpoint.filename)
|
|
|
|
yield {
|
2023-01-29 07:20:19 +00:00
|
|
|
"name": checkpoint.name_for_extra,
|
2023-01-28 19:52:27 +00:00
|
|
|
"filename": path,
|
2023-03-11 12:27:42 +00:00
|
|
|
"preview": self.find_preview(path),
|
|
|
|
"description": self.find_description(path),
|
2023-01-29 22:41:23 +00:00
|
|
|
"search_term": self.search_terms_from_path(checkpoint.filename) + " " + (checkpoint.sha256 or ""),
|
2023-01-28 19:52:27 +00:00
|
|
|
"onclick": '"' + html.escape(f"""return selectCheckpoint({json.dumps(name)})""") + '"',
|
2023-03-11 12:46:20 +00:00
|
|
|
"local_preview": f"{path}.{shared.opts.samples_format}",
|
2023-06-02 20:12:24 +00:00
|
|
|
"sort_keys": {'default': index, **self.get_sort_keys(checkpoint.filename)},
|
|
|
|
|
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
|
|
|
|