mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-22 05:32:12 -03:00
66 lines
2.5 KiB
Python
66 lines
2.5 KiB
Python
import logging
|
|
from typing import List
|
|
|
|
from ..utils.models import LoraMetadata
|
|
from ..config import config
|
|
from .model_scanner import ModelScanner
|
|
from .model_hash_index import ModelHashIndex # Changed from LoraHashIndex to ModelHashIndex
|
|
import sys
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
class LoraScanner(ModelScanner):
|
|
"""Service for scanning and managing LoRA files"""
|
|
|
|
def __init__(self):
|
|
# Define supported file extensions
|
|
file_extensions = {'.safetensors'}
|
|
|
|
# Initialize parent class with ModelHashIndex
|
|
super().__init__(
|
|
model_type="lora",
|
|
model_class=LoraMetadata,
|
|
file_extensions=file_extensions,
|
|
hash_index=ModelHashIndex() # Changed from LoraHashIndex to ModelHashIndex
|
|
)
|
|
|
|
def get_model_roots(self) -> List[str]:
|
|
"""Get lora root directories"""
|
|
return config.loras_roots
|
|
|
|
async def diagnose_hash_index(self):
|
|
"""Diagnostic method to verify hash index functionality"""
|
|
logger.debug("\n\n*** DIAGNOSING LORA HASH INDEX ***\n\n")
|
|
|
|
# First check if the hash index has any entries
|
|
if hasattr(self, '_hash_index'):
|
|
index_entries = len(self._hash_index._hash_to_path)
|
|
logger.debug(f"Hash index has {index_entries} entries")
|
|
|
|
# Print a few example entries if available
|
|
if index_entries > 0:
|
|
logger.debug("\nSample hash index entries:")
|
|
count = 0
|
|
for hash_val, path in self._hash_index._hash_to_path.items():
|
|
if count < 5: # Just show the first 5
|
|
logger.debug(f"Hash: {hash_val[:8]}... -> Path: {path}")
|
|
count += 1
|
|
else:
|
|
break
|
|
else:
|
|
logger.debug("Hash index not initialized")
|
|
|
|
# Try looking up by a known hash for testing
|
|
if not hasattr(self, '_hash_index') or not self._hash_index._hash_to_path:
|
|
logger.debug("No hash entries to test lookup with")
|
|
return
|
|
|
|
test_hash = next(iter(self._hash_index._hash_to_path.keys()))
|
|
test_path = self._hash_index.get_path(test_hash)
|
|
logger.debug(f"\nTest lookup by hash: {test_hash[:8]}... -> {test_path}")
|
|
|
|
# Also test reverse lookup
|
|
test_hash_result = self._hash_index.get_hash(test_path)
|
|
logger.debug(f"Test reverse lookup: {test_path} -> {test_hash_result[:8]}...\n\n")
|
|
|