From 510d476323bbafb2c31fcd8e3dd4a10672003a71 Mon Sep 17 00:00:00 2001 From: Will Miao <13051207myq@gmail.com> Date: Sun, 7 Sep 2025 10:05:30 +0800 Subject: [PATCH] feat(civitai): enhance LoRA matching by extracting hashes from metadata --- py/recipes/parsers/civitai_image.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/py/recipes/parsers/civitai_image.py b/py/recipes/parsers/civitai_image.py index a4fd2c6f..37c9cc25 100644 --- a/py/recipes/parsers/civitai_image.py +++ b/py/recipes/parsers/civitai_image.py @@ -53,6 +53,14 @@ class CivitaiApiMetadataParser(RecipeMetadataParser): # Track already added LoRAs to prevent duplicates added_loras = {} # key: model_version_id or hash, value: index in result["loras"] + # Extract hash information from hashes field for LoRA matching + lora_hashes = {} + if "hashes" in metadata and isinstance(metadata["hashes"], dict): + for key, hash_value in metadata["hashes"].items(): + if key.startswith("LORA:"): + lora_name = key.replace("LORA:", "") + lora_hashes[lora_name] = hash_value + # Extract prompt and negative prompt if "prompt" in metadata: result["gen_params"]["prompt"] = metadata["prompt"] @@ -101,6 +109,10 @@ class CivitaiApiMetadataParser(RecipeMetadataParser): if resource.get("type", "lora") == "lora": lora_hash = resource.get("hash", "") + # Try to get hash from the hashes field if not present in resource + if not lora_hash and resource.get("name"): + lora_hash = lora_hashes.get(resource["name"], "") + # Skip LoRAs without proper identification (hash or modelVersionId) if not lora_hash and not resource.get("modelVersionId"): logger.debug(f"Skipping LoRA resource '{resource.get('name', 'Unknown')}' - no hash or modelVersionId")