mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-22 05:32:12 -03:00
- Implemented the base class `RecipeMetadataParser` for parsing recipe metadata from user comments. - Created a factory class `RecipeParserFactory` to instantiate appropriate parser based on user comment content. - Developed multiple parser classes: `ComfyMetadataParser`, `AutomaticMetadataParser`, `MetaFormatParser`, and `RecipeFormatParser` to handle different metadata formats. - Introduced constants for generation parameters and valid LoRA types. - Enhanced error handling and logging throughout the parsing process. - Added functionality to populate LoRA and checkpoint information from Civitai API responses. - Structured the output of parsed metadata to include prompts, LoRAs, generation parameters, and model information.
44 lines
1.4 KiB
Python
44 lines
1.4 KiB
Python
"""Factory for creating recipe metadata parsers."""
|
|
|
|
import logging
|
|
from .parsers import (
|
|
RecipeFormatParser,
|
|
ComfyMetadataParser,
|
|
MetaFormatParser,
|
|
AutomaticMetadataParser
|
|
)
|
|
from .base import RecipeMetadataParser
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
class RecipeParserFactory:
|
|
"""Factory for creating recipe metadata parsers"""
|
|
|
|
@staticmethod
|
|
def create_parser(user_comment: str) -> RecipeMetadataParser:
|
|
"""
|
|
Create appropriate parser based on the user comment content
|
|
|
|
Args:
|
|
user_comment: The EXIF UserComment string from the image
|
|
|
|
Returns:
|
|
Appropriate RecipeMetadataParser implementation
|
|
"""
|
|
# Try ComfyMetadataParser first since it requires valid JSON
|
|
try:
|
|
if ComfyMetadataParser().is_metadata_matching(user_comment):
|
|
return ComfyMetadataParser()
|
|
except Exception:
|
|
# If JSON parsing fails, move on to other parsers
|
|
pass
|
|
|
|
if RecipeFormatParser().is_metadata_matching(user_comment):
|
|
return RecipeFormatParser()
|
|
elif AutomaticMetadataParser().is_metadata_matching(user_comment):
|
|
return AutomaticMetadataParser()
|
|
elif MetaFormatParser().is_metadata_matching(user_comment):
|
|
return MetaFormatParser()
|
|
else:
|
|
return None
|