Refactor recipe processing in RecipeRoutes to enhance LoRA handling. Introduce base model counting logic to determine the most common base model from LoRAs, and streamline the collection of LoRA metadata. Remove outdated metadata update method from RecipeScanner to improve code clarity and maintainability.

This commit is contained in:
Will Miao
2025-03-16 18:56:27 +08:00
parent 22085e5174
commit 3338c17e8f
2 changed files with 12 additions and 72 deletions

View File

@@ -217,9 +217,9 @@ class RecipeRoutes:
loras = []
base_model = None
# Set base model from checkpoint if available
if checkpoint:
base_model = checkpoint.get('modelName', '')
# Process LoRAs and collect base models
base_model_counts = {}
loras = []
# Process LoRAs
for resource in civitai_resources:
@@ -278,8 +278,11 @@ class RecipeRoutes:
if 'images' in civitai_info and civitai_info['images']:
lora_entry['thumbnailUrl'] = civitai_info['images'][0].get('url', '')
# Get base model
lora_entry['baseModel'] = civitai_info.get('baseModel', '')
# Get base model and update counts
current_base_model = civitai_info.get('baseModel', '')
lora_entry['baseModel'] = current_base_model
if current_base_model:
base_model_counts[current_base_model] = base_model_counts.get(current_base_model, 0) + 1
# Get download URL
lora_entry['downloadUrl'] = civitai_info.get('downloadUrl', '')
@@ -290,6 +293,10 @@ class RecipeRoutes:
loras.append(lora_entry)
# Set base_model to the most common one from civitai_info
if base_model_counts:
base_model = max(base_model_counts.items(), key=lambda x: x[1])[0]
# Extract generation parameters for recipe metadata
gen_params = {
'prompt': metadata.get('prompt', ''),