2023-01-29 03:52:27 +08:00
|
|
|
import html
|
|
|
|
import json
|
|
|
|
import os
|
|
|
|
import urllib.parse
|
|
|
|
|
|
|
|
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-30 06:41:23 +08:00
|
|
|
checkpoint: sd_models.CheckpointInfo
|
2023-01-29 15:20:19 +08:00
|
|
|
for name, checkpoint in sd_models.checkpoints_list.items():
|
2023-01-29 03:52:27 +08:00
|
|
|
path, ext = os.path.splitext(checkpoint.filename)
|
|
|
|
previews = [path + ".png", path + ".preview.png"]
|
|
|
|
|
|
|
|
preview = None
|
|
|
|
for file in previews:
|
|
|
|
if os.path.isfile(file):
|
|
|
|
preview = self.link_preview(file)
|
|
|
|
break
|
|
|
|
|
|
|
|
yield {
|
2023-01-29 15:20:19 +08:00
|
|
|
"name": checkpoint.name_for_extra,
|
2023-01-29 03:52:27 +08:00
|
|
|
"filename": path,
|
|
|
|
"preview": preview,
|
2023-01-30 06:41:23 +08:00
|
|
|
"search_term": self.search_terms_from_path(checkpoint.filename) + " " + (checkpoint.sha256 or ""),
|
2023-01-29 03:52:27 +08:00
|
|
|
"onclick": '"' + html.escape(f"""return selectCheckpoint({json.dumps(name)})""") + '"',
|
|
|
|
"local_preview": path + ".png",
|
|
|
|
}
|
|
|
|
|
|
|
|
def allowed_directories_for_previews(self):
|
2023-01-29 15:32:53 +08:00
|
|
|
return [v for v in [shared.cmd_opts.ckpt_dir, sd_models.model_path] if v is not None]
|
2023-01-29 03:52:27 +08:00
|
|
|
|