Extra networks: support .txt description sidecar file
This commit is contained in:
parent
49b1dc5e07
commit
06f167da37
7 changed files with 31 additions and 0 deletions
|
@ -19,6 +19,7 @@ class ExtraNetworksPageLora(ui_extra_networks.ExtraNetworksPage):
|
||||||
"name": name,
|
"name": name,
|
||||||
"filename": path,
|
"filename": path,
|
||||||
"preview": self._find_preview(path),
|
"preview": self._find_preview(path),
|
||||||
|
"description": self._find_description(path),
|
||||||
"search_term": self.search_terms_from_path(lora_on_disk.filename),
|
"search_term": self.search_terms_from_path(lora_on_disk.filename),
|
||||||
"prompt": json.dumps(f"<lora:{name}:") + " + opts.extra_networks_default_multiplier + " + json.dumps(">"),
|
"prompt": json.dumps(f"<lora:{name}:") + " + opts.extra_networks_default_multiplier + " + json.dumps(">"),
|
||||||
"local_preview": path + ".png",
|
"local_preview": path + ".png",
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
<span style="display:none" class='search_term'>{search_term}</span>
|
<span style="display:none" class='search_term'>{search_term}</span>
|
||||||
</div>
|
</div>
|
||||||
<span class='name'>{name}</span>
|
<span class='name'>{name}</span>
|
||||||
|
<span class='description'>{description}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import glob
|
import glob
|
||||||
import os.path
|
import os.path
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
|
from functools import lru_cache
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
|
@ -131,6 +132,7 @@ class ExtraNetworksPage:
|
||||||
"tabname": json.dumps(tabname),
|
"tabname": json.dumps(tabname),
|
||||||
"local_preview": json.dumps(item["local_preview"]),
|
"local_preview": json.dumps(item["local_preview"]),
|
||||||
"name": item["name"],
|
"name": item["name"],
|
||||||
|
"description": (item.get("description") or ""),
|
||||||
"card_clicked": onclick,
|
"card_clicked": onclick,
|
||||||
"save_card_preview": '"' + html.escape(f"""return saveCardPreview(event, {json.dumps(tabname)}, {json.dumps(item["local_preview"])})""") + '"',
|
"save_card_preview": '"' + html.escape(f"""return saveCardPreview(event, {json.dumps(tabname)}, {json.dumps(item["local_preview"])})""") + '"',
|
||||||
"search_term": item.get("search_term", ""),
|
"search_term": item.get("search_term", ""),
|
||||||
|
@ -147,6 +149,19 @@ class ExtraNetworksPage:
|
||||||
return self.link_preview(file)
|
return self.link_preview(file)
|
||||||
return None
|
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():
|
def intialize():
|
||||||
extra_pages.clear()
|
extra_pages.clear()
|
||||||
|
|
|
@ -20,6 +20,7 @@ class ExtraNetworksPageCheckpoints(ui_extra_networks.ExtraNetworksPage):
|
||||||
"name": checkpoint.name_for_extra,
|
"name": checkpoint.name_for_extra,
|
||||||
"filename": path,
|
"filename": path,
|
||||||
"preview": self._find_preview(path),
|
"preview": self._find_preview(path),
|
||||||
|
"description": self._find_description(path),
|
||||||
"search_term": self.search_terms_from_path(checkpoint.filename) + " " + (checkpoint.sha256 or ""),
|
"search_term": self.search_terms_from_path(checkpoint.filename) + " " + (checkpoint.sha256 or ""),
|
||||||
"onclick": '"' + html.escape(f"""return selectCheckpoint({json.dumps(name)})""") + '"',
|
"onclick": '"' + html.escape(f"""return selectCheckpoint({json.dumps(name)})""") + '"',
|
||||||
"local_preview": path + ".png",
|
"local_preview": path + ".png",
|
||||||
|
|
|
@ -19,6 +19,7 @@ class ExtraNetworksPageHypernetworks(ui_extra_networks.ExtraNetworksPage):
|
||||||
"name": name,
|
"name": name,
|
||||||
"filename": path,
|
"filename": path,
|
||||||
"preview": self._find_preview(path),
|
"preview": self._find_preview(path),
|
||||||
|
"description": self._find_description(path),
|
||||||
"search_term": self.search_terms_from_path(path),
|
"search_term": self.search_terms_from_path(path),
|
||||||
"prompt": json.dumps(f"<hypernet:{name}:") + " + opts.extra_networks_default_multiplier + " + json.dumps(">"),
|
"prompt": json.dumps(f"<hypernet:{name}:") + " + opts.extra_networks_default_multiplier + " + json.dumps(">"),
|
||||||
"local_preview": path + ".png",
|
"local_preview": path + ".png",
|
||||||
|
|
|
@ -19,6 +19,7 @@ class ExtraNetworksPageTextualInversion(ui_extra_networks.ExtraNetworksPage):
|
||||||
"name": embedding.name,
|
"name": embedding.name,
|
||||||
"filename": embedding.filename,
|
"filename": embedding.filename,
|
||||||
"preview": self._find_preview(path),
|
"preview": self._find_preview(path),
|
||||||
|
"description": self._find_description(path),
|
||||||
"search_term": self.search_terms_from_path(embedding.filename),
|
"search_term": self.search_terms_from_path(embedding.filename),
|
||||||
"prompt": json.dumps(embedding.name),
|
"prompt": json.dumps(embedding.name),
|
||||||
"local_preview": path + ".preview.png",
|
"local_preview": path + ".preview.png",
|
||||||
|
|
11
style.css
11
style.css
|
@ -939,6 +939,17 @@ footer {
|
||||||
line-break: anywhere;
|
line-break: anywhere;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.extra-network-cards .card .actions .description {
|
||||||
|
display: block;
|
||||||
|
max-height: 3em;
|
||||||
|
white-space: pre-wrap;
|
||||||
|
line-height: 1.1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.extra-network-cards .card .actions .description:hover {
|
||||||
|
max-height: none;
|
||||||
|
}
|
||||||
|
|
||||||
.extra-network-cards .card .actions:hover .additional{
|
.extra-network-cards .card .actions:hover .additional{
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue