aboutsummaryrefslogtreecommitdiffstats
path: root/modules/ui_extra_networks.py
diff options
context:
space:
mode:
Diffstat (limited to 'modules/ui_extra_networks.py')
-rw-r--r--modules/ui_extra_networks.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/modules/ui_extra_networks.py b/modules/ui_extra_networks.py
index 71f1d81f..cd61a569 100644
--- a/modules/ui_extra_networks.py
+++ b/modules/ui_extra_networks.py
@@ -1,7 +1,9 @@
import glob
import os.path
import urllib.parse
+from functools import lru_cache
from pathlib import Path
+from typing import Optional
from modules import shared
import gradio as gr
@@ -130,6 +132,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 +140,28 @@ class ExtraNetworksPage:
return self.card_page.format(**args)
+ def _find_preview(self, path: str) -> Optional[str]:
+ """
+ Find a preview PNG for a given path (without extension) and call link_preview on it.
+ """
+ for file in [path + ".png", path + ".preview.png"]:
+ if os.path.isfile(file):
+ return self.link_preview(file)
+ return None
+
+ @lru_cache(maxsize=512)
+ def _find_description(self, path: str) -> Optional[str]:
+ """
+ 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()