Skip to content

Commit

Permalink
use lora.loaded_loras if available
Browse files Browse the repository at this point in the history
 * fix for webui 1.5.x
  • Loading branch information
wkpark committed Nov 1, 2023
1 parent 136983e commit 005efb5
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion scripts/gen_hashing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os

import civitai.lib as civitai
from modules import script_callbacks, sd_vae, shared
from modules import script_callbacks, sd_vae, shared, hashes

additional_network_type_map = {
'lora': 'LORA',
Expand Down Expand Up @@ -62,6 +62,30 @@ def add_resource_hashes(params):
short_hash = matching_resource[0]['hash'][:10]
resource_hashes[f'{network_type}:{network_name}'] = short_hash

# check loaded_loras
loaded = []
try:
import lora
loaded = lora.loaded_lora
except Exception
pass
for item in loaded:
name = item.name
if f'lora:{name}' in resource_hashes.keys():
continue

lora_on_disk = item.lora_on_disk if hasattr(item, "lora_on_disk") else item.network_on_disk if hasattr(item, "network_on_disk") else None
if lora_on_disk is None:
continue

hash = hashes.sha256(lora_on_disk.filename, "lora/" + lora_on_disk.name)
if not hash:
continue
short_hash = hash[0:10]

name = name.replace(":", "").replace(",", "")
resource_hashes[f'lora:{name}'] = short_hash

# Check for model hash in generation parameters
model_match = re.search(model_hash_pattern, generation_params)
if hashify_resources and model_match:
Expand Down

0 comments on commit 005efb5

Please sign in to comment.