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-01-29 07:20:19 +00:00
|
|
|
for name, checkpoint in 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)})""") + '"',
|
|
|
|
"local_preview": path + ".png",
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|