improve preview lookups

This commit is contained in:
Vladimir Mandic
2023-11-06 12:19:52 -05:00
parent bf89f75955
commit 28ee8b4d57
7 changed files with 29 additions and 23 deletions
+5 -3
View File
@@ -1,12 +1,14 @@
{
"RunwayML SD 1.5": {
"path": "runwayml/stable-diffusion-v1-5"
"path": "runwayml/stable-diffusion-v1-5",
"preview": "runwayml--stable-diffusion-v1-5.jpg"
},
"StabilityAI SD 2.1": {
"path": "stabilityai/stable-diffusion-2-1-base"
},
"StabilityAI SD-XL 1.0 Base": {
"path": "stabilityai/stable-diffusion-xl-base-1.0"
"path": "stabilityai/stable-diffusion-xl-base-1.0",
"preview": "stabilityai--stable-diffusion-xl-base-1.0.jpg"
},
"Segmind SSD-1B": {
"path": "segmind/SSD-1B"
@@ -38,6 +40,6 @@
"Tsinghua UniDiffuser": {
"path": "thu-ml/unidiffuser-v1",
"desc": "UniDiffuser is a unified diffusion framework to fit all distributions relevant to a set of multi-modal data in one transformer. UniDiffuser is able to perform image, text, text-to-image, image-to-text, and image-text pair generation by setting proper timesteps without additional overhead.\nSpecifically, UniDiffuser employs a variation of transformer, called U-ViT, which parameterizes the joint noise prediction network. Other components perform as encoders and decoders of different modalities, including a pretrained image autoencoder from Stable Diffusion, a pretrained image ViT-B/32 CLIP encoder, a pretrained text ViT-L CLIP encoder, and a GPT-2 text decoder finetuned by ourselves.",
"preview": "unidiffuser-v1.jpg"
"preview": "thu-ml--unidiffuser-v1.jpg"
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Before

Width:  |  Height:  |  Size: 47 KiB

After

Width:  |  Height:  |  Size: 47 KiB

+2 -2
View File
@@ -152,7 +152,7 @@ def context_hypertile_vae(p):
log.warning(f'Hypertile VAE disabled: width={width} height={height} are not divisible by 8')
return nullcontext()
if vae is None:
shared.log.warning('Hypertile VAE is enabled but no VAE model was found')
# shared.log.warning('Hypertile VAE is enabled but no VAE model was found')
return nullcontext()
else:
shared.log.info(f'Applying hypertile: vae={shared.opts.hypertile_vae_tile}')
@@ -178,7 +178,7 @@ def context_hypertile_unet(p):
log.warning(f'Hypertile UNet disabled: width={width} height={height} are not divisible by 8')
return nullcontext()
if unet is None:
shared.log.warning('Hypertile UNet is enabled but no Unet model was found')
# shared.log.warning('Hypertile UNet is enabled but no Unet model was found')
return nullcontext()
else:
shared.log.info(f'Applying hypertile: unet={shared.opts.hypertile_unet_tile}')
+19 -16
View File
@@ -252,7 +252,7 @@ class ExtraNetworksPage:
if not self.is_empty(tgt):
subdirs[subdir] = 1
subdirs = OrderedDict(sorted(subdirs.items()))
if shared.backend == shared.Backend.DIFFUSERS:
if shared.backend == shared.Backend.DIFFUSERS and self.name == 'model':
subdirs['Reference'] = 1
subdirs[os.path.basename(shared.opts.diffusers_dir)] = 1
subdirs.move_to_end(os.path.basename(shared.opts.diffusers_dir))
@@ -314,26 +314,27 @@ class ExtraNetworksPage:
return ""
def find_preview_file(self, path):
fn = os.path.splitext(path)[0]
preview_extensions = ["jpg", "jpeg", "png", "webp", "tiff", "jp2"]
files = listdir(os.path.dirname(path))
for file in [f'{fn}{mid}{ext}' for ext in preview_extensions for mid in ['.thumb.', '.preview.', '.']]:
if file in files:
return file
return 'html/card-no-preview.png'
def find_preview(self, path):
if path is None:
return self.link_preview('html/card-no-preview.png')
fn = os.path.splitext(path)[0]
return 'html/card-no-preview.png'
if shared.opts.diffusers_dir in path:
path = os.path.relpath(path, shared.opts.diffusers_dir)
ref = os.path.join(paths.models_path, 'Reference')
fn = os.path.join(ref, path.replace('models--', '').replace('\\', '/').split('/')[0])
files = listdir(ref)
else:
files = listdir(os.path.dirname(path))
fn = os.path.splitext(path)[0]
preview_extensions = ["jpg", "jpeg", "png", "webp", "tiff", "jp2"]
files = listdir(os.path.dirname(path))
for file in [f'{fn}{mid}{ext}' for ext in preview_extensions for mid in ['.thumb.', '.', '.preview.']]:
if file in files:
if '.thumb.' not in file:
self.missing_thumbs.append(file)
return self.link_preview(file)
return self.link_preview('html/card-no-preview.png')
return file
return 'html/card-no-preview.png'
def find_preview(self, path):
preview_file = self.find_preview_file(path)
return self.link_preview(preview_file)
def find_description(self, path, info=None):
t0 = time.time()
@@ -650,6 +651,8 @@ def create_ui(container, button_parent, tabname, skip_indexing = False):
if ui.last_item.preview.startswith('data:'):
b64str = ui.last_item.preview.split(',',1)[1]
img = Image.open(io.BytesIO(base64.b64decode(b64str)))
elif hasattr(item, 'local_preview') and os.path.exists(item.local_preview):
img = item.local_preview
else:
img = page.find_preview_file(item.filename)
lora = ''
@@ -657,7 +660,7 @@ def create_ui(container, button_parent, tabname, skip_indexing = False):
style = ''
note = ''
if not os.path.exists(item.filename):
note = f'<br><h3>File is not yet saved</h3>Target filename: {item.filename}'
note = f'<br>Target filename: {item.filename}'
if page.title == 'Model':
merge = len(list(meta.get('sd_merge_models', {})))
if merge > 0:
+3 -2
View File
@@ -18,14 +18,15 @@ class ExtraNetworksPageCheckpoints(ui_extra_networks.ExtraNetworksPage):
reference_models = shared.readfile(os.path.join('html', 'reference.json'))
for k, v in reference_models.items():
name = os.path.join(reference_dir, k)
preview = v.get('preview', v['path'])
yield {
"type": 'Model',
"name": name,
"title": name,
"filename": v['path'],
"search_term": self.search_terms_from_path(name),
"preview": self.find_preview(os.path.join(reference_dir, os.path.basename(v['path']))),
"local_preview": f"{os.path.splitext(name)[0]}.{shared.opts.samples_format}",
"preview": self.find_preview(os.path.join(reference_dir, preview)),
"local_preview": self.find_preview_file(os.path.join(reference_dir, preview)),
"onclick": '"' + html.escape(f"""return selectReference({json.dumps(v['path'])})""") + '"',
"hash": None,
"mtime": 0,