Skip to content

Commit

Permalink
return nothing if not found
Browse files Browse the repository at this point in the history
  • Loading branch information
w-e-w committed Sep 9, 2023
1 parent f5959c1 commit af4a03b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
5 changes: 3 additions & 2 deletions extensions-builtin/Lora/ui_extra_networks_lora.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ def refresh(self):
networks.list_available_networks()

def create_item(self, name, index=None, enable_filter=True):
lora_on_disk = networks.available_networks.get(name)
lora_on_disk = networks.available_networks.get(name, None)
if lora_on_disk is None:
return

path, ext = os.path.splitext(lora_on_disk.filename)

Expand Down Expand Up @@ -69,7 +71,6 @@ def list_items(self):
names = list(networks.available_networks)
for index, name in enumerate(names):
item = self.create_item(name, index)

if item is not None:
yield item

Expand Down
9 changes: 7 additions & 2 deletions modules/ui_extra_networks_checkpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ def refresh(self):
shared.refresh_checkpoints()

def create_item(self, name, index=None, enable_filter=True):
checkpoint: sd_models.CheckpointInfo = sd_models.checkpoint_aliases.get(name)
checkpoint: sd_models.CheckpointInfo = sd_models.checkpoint_aliases.get(name, None)
if checkpoint is None():
return

path, ext = os.path.splitext(checkpoint.filename)
return {
"name": checkpoint.name_for_extra,
Expand All @@ -32,7 +35,9 @@ def create_item(self, name, index=None, enable_filter=True):
def list_items(self):
names = list(sd_models.checkpoints_list)
for index, name in enumerate(names):
yield self.create_item(name, index)
item = self.create_item(name, index)
if item is not None:
yield item

def allowed_directories_for_previews(self):
return [v for v in [shared.cmd_opts.ckpt_dir, sd_models.model_path] if v is not None]
Expand Down
9 changes: 7 additions & 2 deletions modules/ui_extra_networks_hypernets.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ def refresh(self):
shared.reload_hypernetworks()

def create_item(self, name, index=None, enable_filter=True):
full_path = shared.hypernetworks[name]
full_path = shared.hypernetworks.get(name, None)
if full_path is None:
return

path, ext = os.path.splitext(full_path)
sha256 = sha256_from_cache(full_path, f'hypernet/{name}')
shorthash = sha256[0:10] if sha256 else None
Expand All @@ -33,7 +36,9 @@ def create_item(self, name, index=None, enable_filter=True):
def list_items(self):
names = list(shared.hypernetworks)
for index, name in enumerate(names):
yield self.create_item(name, index)
item = self.create_item(name, index)
if item is not None:
yield item

def allowed_directories_for_previews(self):
return [shared.cmd_opts.hypernetwork_dir]
Expand Down
8 changes: 6 additions & 2 deletions modules/ui_extra_networks_textual_inversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ def refresh(self):
sd_hijack.model_hijack.embedding_db.load_textual_inversion_embeddings(force_reload=True)

def create_item(self, name, index=None, enable_filter=True):
embedding = sd_hijack.model_hijack.embedding_db.word_embeddings.get(name)
embedding = sd_hijack.model_hijack.embedding_db.word_embeddings.get(name, None)
if embedding is None:
return

path, ext = os.path.splitext(embedding.filename)
return {
Expand All @@ -31,7 +33,9 @@ def create_item(self, name, index=None, enable_filter=True):
def list_items(self):
names = list(sd_hijack.model_hijack.embedding_db.word_embeddings)
for index, name in enumerate(names):
yield self.create_item(name, index)
item = self.create_item(name, index)
if item is not None:
yield item

def allowed_directories_for_previews(self):
return list(sd_hijack.model_hijack.embedding_db.embedding_dirs)

0 comments on commit af4a03b

Please sign in to comment.