Merge branch 'master' of https://github.com/AUTOMATIC1111/stable-diffusion-webui
This commit is contained in:
commit
c46f3ad98b
@ -27,6 +27,7 @@ class ExtraNetworksPageLora(ui_extra_networks.ExtraNetworksPage):
|
|||||||
"name": name,
|
"name": name,
|
||||||
"filename": path,
|
"filename": path,
|
||||||
"preview": preview,
|
"preview": preview,
|
||||||
|
"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",
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
<ul>
|
<ul>
|
||||||
<a href="#" title="replace preview image with currently selected in gallery" onclick={save_card_preview}>replace preview</a>
|
<a href="#" title="replace preview image with currently selected in gallery" onclick={save_card_preview}>replace preview</a>
|
||||||
</ul>
|
</ul>
|
||||||
|
<span style="display:none" class='search_term'>{search_term}</span>
|
||||||
</div>
|
</div>
|
||||||
<span class='name'>{name}</span>
|
<span class='name'>{name}</span>
|
||||||
</div>
|
</div>
|
||||||
|
@ -16,7 +16,7 @@ function setupExtraNetworksForTab(tabname){
|
|||||||
searchTerm = search.value.toLowerCase()
|
searchTerm = search.value.toLowerCase()
|
||||||
|
|
||||||
gradioApp().querySelectorAll('#'+tabname+'_extra_tabs div.card').forEach(function(elem){
|
gradioApp().querySelectorAll('#'+tabname+'_extra_tabs div.card').forEach(function(elem){
|
||||||
text = elem.querySelector('.name').textContent.toLowerCase()
|
text = elem.querySelector('.name').textContent.toLowerCase() + " " + elem.querySelector('.search_term').textContent.toLowerCase()
|
||||||
elem.style.display = text.indexOf(searchTerm) == -1 ? "none" : ""
|
elem.style.display = text.indexOf(searchTerm) == -1 ? "none" : ""
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
@ -96,3 +96,12 @@ function saveCardPreview(event, tabname, filename){
|
|||||||
event.stopPropagation()
|
event.stopPropagation()
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function extraNetworksSearchButton(tabs_id, event){
|
||||||
|
searchTextarea = gradioApp().querySelector("#" + tabs_id + ' > div > textarea')
|
||||||
|
button = event.target
|
||||||
|
text = button.classList.contains("search-all") ? "" : button.textContent.trim()
|
||||||
|
|
||||||
|
searchTextarea.value = text
|
||||||
|
updateInput(searchTextarea)
|
||||||
|
}
|
@ -36,6 +36,8 @@ def image_grid(imgs, batch_size=1, rows=None):
|
|||||||
else:
|
else:
|
||||||
rows = math.sqrt(len(imgs))
|
rows = math.sqrt(len(imgs))
|
||||||
rows = round(rows)
|
rows = round(rows)
|
||||||
|
if rows > len(imgs):
|
||||||
|
rows = len(imgs)
|
||||||
|
|
||||||
cols = math.ceil(len(imgs) / rows)
|
cols = math.ceil(len(imgs) / rows)
|
||||||
|
|
||||||
|
@ -450,8 +450,6 @@ def create_infotext(p, all_prompts, all_seeds, all_subseeds, comments=None, iter
|
|||||||
"Size": f"{p.width}x{p.height}",
|
"Size": f"{p.width}x{p.height}",
|
||||||
"Model hash": getattr(p, 'sd_model_hash', None if not opts.add_model_hash_to_info or not shared.sd_model.sd_model_hash else shared.sd_model.sd_model_hash),
|
"Model hash": getattr(p, 'sd_model_hash', None if not opts.add_model_hash_to_info or not shared.sd_model.sd_model_hash else shared.sd_model.sd_model_hash),
|
||||||
"Model": (None if not opts.add_model_name_to_info or not shared.sd_model.sd_checkpoint_info.model_name else shared.sd_model.sd_checkpoint_info.model_name.replace(',', '').replace(':', '')),
|
"Model": (None if not opts.add_model_name_to_info or not shared.sd_model.sd_checkpoint_info.model_name else shared.sd_model.sd_checkpoint_info.model_name.replace(',', '').replace(':', '')),
|
||||||
"Batch size": (None if p.batch_size < 2 else p.batch_size),
|
|
||||||
"Batch pos": (None if p.batch_size < 2 else position_in_batch),
|
|
||||||
"Variation seed": (None if p.subseed_strength == 0 else all_subseeds[index]),
|
"Variation seed": (None if p.subseed_strength == 0 else all_subseeds[index]),
|
||||||
"Variation seed strength": (None if p.subseed_strength == 0 else p.subseed_strength),
|
"Variation seed strength": (None if p.subseed_strength == 0 else p.subseed_strength),
|
||||||
"Seed resize from": (None if p.seed_resize_from_w == 0 or p.seed_resize_from_h == 0 else f"{p.seed_resize_from_w}x{p.seed_resize_from_h}"),
|
"Seed resize from": (None if p.seed_resize_from_w == 0 or p.seed_resize_from_h == 0 else f"{p.seed_resize_from_w}x{p.seed_resize_from_h}"),
|
||||||
|
@ -41,6 +41,7 @@ class CheckpointInfo:
|
|||||||
name = name[1:]
|
name = name[1:]
|
||||||
|
|
||||||
self.name = name
|
self.name = name
|
||||||
|
self.name_for_extra = os.path.splitext(os.path.basename(filename))[0]
|
||||||
self.model_name = os.path.splitext(name.replace("/", "_").replace("\\", "_"))[0]
|
self.model_name = os.path.splitext(name.replace("/", "_").replace("\\", "_"))[0]
|
||||||
self.hash = model_hash(filename)
|
self.hash = model_hash(filename)
|
||||||
|
|
||||||
|
@ -112,6 +112,7 @@ class EmbeddingDatabase:
|
|||||||
self.skipped_embeddings = {}
|
self.skipped_embeddings = {}
|
||||||
self.expected_shape = -1
|
self.expected_shape = -1
|
||||||
self.embedding_dirs = {}
|
self.embedding_dirs = {}
|
||||||
|
self.previously_displayed_embeddings = ()
|
||||||
|
|
||||||
def add_embedding_dir(self, path):
|
def add_embedding_dir(self, path):
|
||||||
self.embedding_dirs[path] = DirWithTextualInversionEmbeddings(path)
|
self.embedding_dirs[path] = DirWithTextualInversionEmbeddings(path)
|
||||||
@ -228,9 +229,12 @@ class EmbeddingDatabase:
|
|||||||
self.load_from_dir(embdir)
|
self.load_from_dir(embdir)
|
||||||
embdir.update()
|
embdir.update()
|
||||||
|
|
||||||
print(f"Textual inversion embeddings loaded({len(self.word_embeddings)}): {', '.join(self.word_embeddings.keys())}")
|
displayed_embeddings = (tuple(self.word_embeddings.keys()), tuple(self.skipped_embeddings.keys()))
|
||||||
if len(self.skipped_embeddings) > 0:
|
if self.previously_displayed_embeddings != displayed_embeddings:
|
||||||
print(f"Textual inversion embeddings skipped({len(self.skipped_embeddings)}): {', '.join(self.skipped_embeddings.keys())}")
|
self.previously_displayed_embeddings = displayed_embeddings
|
||||||
|
print(f"Textual inversion embeddings loaded({len(self.word_embeddings)}): {', '.join(self.word_embeddings.keys())}")
|
||||||
|
if len(self.skipped_embeddings) > 0:
|
||||||
|
print(f"Textual inversion embeddings skipped({len(self.skipped_embeddings)}): {', '.join(self.skipped_embeddings.keys())}")
|
||||||
|
|
||||||
def find_embedding_at_position(self, tokens, offset):
|
def find_embedding_at_position(self, tokens, offset):
|
||||||
token = tokens[offset]
|
token = tokens[offset]
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import glob
|
||||||
import os.path
|
import os.path
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@ -50,10 +51,41 @@ class ExtraNetworksPage:
|
|||||||
def link_preview(self, filename):
|
def link_preview(self, filename):
|
||||||
return "./sd_extra_networks/thumb?filename=" + urllib.parse.quote(filename.replace('\\', '/')) + "&mtime=" + str(os.path.getmtime(filename))
|
return "./sd_extra_networks/thumb?filename=" + urllib.parse.quote(filename.replace('\\', '/')) + "&mtime=" + str(os.path.getmtime(filename))
|
||||||
|
|
||||||
|
def search_terms_from_path(self, filename, possible_directories=None):
|
||||||
|
abspath = os.path.abspath(filename)
|
||||||
|
|
||||||
|
for parentdir in (possible_directories if possible_directories is not None else self.allowed_directories_for_previews()):
|
||||||
|
parentdir = os.path.abspath(parentdir)
|
||||||
|
if abspath.startswith(parentdir):
|
||||||
|
return abspath[len(parentdir):].replace('\\', '/')
|
||||||
|
|
||||||
|
return ""
|
||||||
|
|
||||||
def create_html(self, tabname):
|
def create_html(self, tabname):
|
||||||
view = shared.opts.extra_networks_default_view
|
view = shared.opts.extra_networks_default_view
|
||||||
items_html = ''
|
items_html = ''
|
||||||
|
|
||||||
|
subdirs = {}
|
||||||
|
for parentdir in [os.path.abspath(x) for x in self.allowed_directories_for_previews()]:
|
||||||
|
for x in glob.glob(os.path.join(parentdir, '**/*'), recursive=True):
|
||||||
|
if not os.path.isdir(x):
|
||||||
|
continue
|
||||||
|
|
||||||
|
subdir = os.path.abspath(x)[len(parentdir):].replace("\\", "/")
|
||||||
|
while subdir.startswith("/"):
|
||||||
|
subdir = subdir[1:]
|
||||||
|
|
||||||
|
subdirs[subdir] = 1
|
||||||
|
|
||||||
|
if subdirs:
|
||||||
|
subdirs = {"": 1, **subdirs}
|
||||||
|
|
||||||
|
subdirs_html = "".join([f"""
|
||||||
|
<button class='gr-button gr-button-lg gr-button-secondary{" search-all" if subdir=="" else ""}' onclick='extraNetworksSearchButton("{tabname}_extra_tabs", event)'>
|
||||||
|
{html.escape(subdir if subdir!="" else "all")}
|
||||||
|
</button>
|
||||||
|
""" for subdir in subdirs])
|
||||||
|
|
||||||
for item in self.list_items():
|
for item in self.list_items():
|
||||||
items_html += self.create_html_for_item(item, tabname)
|
items_html += self.create_html_for_item(item, tabname)
|
||||||
|
|
||||||
@ -62,6 +94,9 @@ class ExtraNetworksPage:
|
|||||||
items_html = shared.html("extra-networks-no-cards.html").format(dirs=dirs)
|
items_html = shared.html("extra-networks-no-cards.html").format(dirs=dirs)
|
||||||
|
|
||||||
res = f"""
|
res = f"""
|
||||||
|
<div id='{tabname}_{self.name}_subdirs' class='extra-network-subdirs extra-network-subdirs-{view}'>
|
||||||
|
{subdirs_html}
|
||||||
|
</div>
|
||||||
<div id='{tabname}_{self.name}_cards' class='extra-network-{view}'>
|
<div id='{tabname}_{self.name}_cards' class='extra-network-{view}'>
|
||||||
{items_html}
|
{items_html}
|
||||||
</div>
|
</div>
|
||||||
@ -90,6 +125,7 @@ class ExtraNetworksPage:
|
|||||||
"name": item["name"],
|
"name": item["name"],
|
||||||
"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", ""),
|
||||||
}
|
}
|
||||||
|
|
||||||
return self.card_page.format(**args)
|
return self.card_page.format(**args)
|
||||||
|
@ -14,8 +14,7 @@ class ExtraNetworksPageCheckpoints(ui_extra_networks.ExtraNetworksPage):
|
|||||||
shared.refresh_checkpoints()
|
shared.refresh_checkpoints()
|
||||||
|
|
||||||
def list_items(self):
|
def list_items(self):
|
||||||
for name, checkpoint1 in sd_models.checkpoints_list.items():
|
for name, checkpoint in sd_models.checkpoints_list.items():
|
||||||
checkpoint: sd_models.CheckpointInfo = checkpoint1
|
|
||||||
path, ext = os.path.splitext(checkpoint.filename)
|
path, ext = os.path.splitext(checkpoint.filename)
|
||||||
previews = [path + ".png", path + ".preview.png"]
|
previews = [path + ".png", path + ".preview.png"]
|
||||||
|
|
||||||
@ -26,13 +25,14 @@ class ExtraNetworksPageCheckpoints(ui_extra_networks.ExtraNetworksPage):
|
|||||||
break
|
break
|
||||||
|
|
||||||
yield {
|
yield {
|
||||||
"name": checkpoint.model_name,
|
"name": checkpoint.name_for_extra,
|
||||||
"filename": path,
|
"filename": path,
|
||||||
"preview": preview,
|
"preview": preview,
|
||||||
|
"search_term": self.search_terms_from_path(checkpoint.filename),
|
||||||
"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",
|
||||||
}
|
}
|
||||||
|
|
||||||
def allowed_directories_for_previews(self):
|
def allowed_directories_for_previews(self):
|
||||||
return [shared.cmd_opts.ckpt_dir, sd_models.model_path]
|
return [v for v in [shared.cmd_opts.ckpt_dir, sd_models.model_path] if v is not None]
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@ class ExtraNetworksPageHypernetworks(ui_extra_networks.ExtraNetworksPage):
|
|||||||
"name": name,
|
"name": name,
|
||||||
"filename": path,
|
"filename": path,
|
||||||
"preview": preview,
|
"preview": preview,
|
||||||
|
"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",
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ class ExtraNetworksPageTextualInversion(ui_extra_networks.ExtraNetworksPage):
|
|||||||
"name": embedding.name,
|
"name": embedding.name,
|
||||||
"filename": embedding.filename,
|
"filename": embedding.filename,
|
||||||
"preview": preview,
|
"preview": preview,
|
||||||
|
"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",
|
||||||
}
|
}
|
||||||
|
@ -807,7 +807,13 @@ footer {
|
|||||||
margin: 0.3em;
|
margin: 0.3em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.extra-network-subdirs{
|
||||||
|
padding: 0.2em 0.35em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.extra-network-subdirs button{
|
||||||
|
margin: 0 0.15em;
|
||||||
|
}
|
||||||
|
|
||||||
#txt2img_extra_networks .search, #img2img_extra_networks .search{
|
#txt2img_extra_networks .search, #img2img_extra_networks .search{
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
|
Loading…
Reference in New Issue
Block a user