diff options
author | Vespinian <vespinian@proton.me> | 2023-03-11 17:33:35 +0000 |
---|---|---|
committer | Vespinian <vespinian@proton.me> | 2023-03-11 17:33:35 +0000 |
commit | 46f9fe3cd6b7be712d85cdfc2cdff7ac3fe878b5 (patch) | |
tree | a134b22d856ab534c497b04c0d7ec87935cfcce7 /modules/ui_extra_networks.py | |
parent | 2174f58daee1e077eec1125e196d34cc93dbaf23 (diff) | |
parent | 94ffa9fc5386e51f20692ab46906135e8de33110 (diff) | |
download | stable-diffusion-webui-gfx803-46f9fe3cd6b7be712d85cdfc2cdff7ac3fe878b5.tar.gz stable-diffusion-webui-gfx803-46f9fe3cd6b7be712d85cdfc2cdff7ac3fe878b5.tar.bz2 stable-diffusion-webui-gfx803-46f9fe3cd6b7be712d85cdfc2cdff7ac3fe878b5.zip |
Merge branch 'master' of https://github.com/AUTOMATIC1111/stable-diffusion-webui
Diffstat (limited to 'modules/ui_extra_networks.py')
-rw-r--r-- | modules/ui_extra_networks.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/modules/ui_extra_networks.py b/modules/ui_extra_networks.py index 71f1d81f..85f0af4c 100644 --- a/modules/ui_extra_networks.py +++ b/modules/ui_extra_networks.py @@ -130,6 +130,7 @@ class ExtraNetworksPage: "tabname": json.dumps(tabname),
"local_preview": json.dumps(item["local_preview"]),
"name": item["name"],
+ "description": (item.get("description") or ""),
"card_clicked": onclick,
"save_card_preview": '"' + html.escape(f"""return saveCardPreview(event, {json.dumps(tabname)}, {json.dumps(item["local_preview"])})""") + '"',
"search_term": item.get("search_term", ""),
@@ -137,6 +138,35 @@ class ExtraNetworksPage: return self.card_page.format(**args)
+ def find_preview(self, path):
+ """
+ Find a preview PNG for a given path (without extension) and call link_preview on it.
+ """
+
+ preview_extensions = ["png", "jpg", "webp"]
+ if shared.opts.samples_format not in preview_extensions:
+ preview_extensions.append(shared.opts.samples_format)
+
+ potential_files = sum([[path + "." + ext, path + ".preview." + ext] for ext in preview_extensions], [])
+
+ for file in potential_files:
+ if os.path.isfile(file):
+ return self.link_preview(file)
+
+ return None
+
+ def find_description(self, path):
+ """
+ Find and read a description file for a given path (without extension).
+ """
+ for file in [f"{path}.txt", f"{path}.description.txt"]:
+ try:
+ with open(file, "r", encoding="utf-8", errors="replace") as f:
+ return f.read()
+ except OSError:
+ pass
+ return None
+
def intialize():
extra_pages.clear()
|