2023-01-28 12:52:27 -07: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 15:41:23 -07:00
|
|
|
checkpoint: sd_models.CheckpointInfo
|
2023-01-29 00:20:19 -07:00
|
|
|
for name, checkpoint in sd_models.checkpoints_list.items():
|
2023-01-28 12:52:27 -07:00
|
|
|
path, ext = os.path.splitext(checkpoint.filename)
|
|
|
|
yield {
|
2023-01-29 00:20:19 -07:00
|
|
|
"name": checkpoint.name_for_extra,
|
2023-01-28 12:52:27 -07:00
|
|
|
"filename": path,
|
2023-03-11 05:27:42 -07:00
|
|
|
"preview": self.find_preview(path),
|
|
|
|
"description": self.find_description(path),
|
2023-01-29 15:41:23 -07:00
|
|
|
"search_term": self.search_terms_from_path(checkpoint.filename) + " " + (checkpoint.sha256 or ""),
|
2023-01-28 12:52:27 -07:00
|
|
|
"onclick": '"' + html.escape(f"""return selectCheckpoint({json.dumps(name)})""") + '"',
|
2023-03-11 05:46:20 -07:00
|
|
|
"local_preview": f"{path}.{shared.opts.samples_format}",
|
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
|
|
|
|