Spaces:
Sleeping
Sleeping
| """ | |
| Base plugin interface for all backend plugins. | |
| All backends (ComfyUI, OmniGen2, Gemini, etc.) implement this interface. | |
| """ | |
| from abc import ABC, abstractmethod | |
| from typing import Any, Dict, Optional, List | |
| from PIL import Image | |
| from pathlib import Path | |
| import yaml | |
| class BaseBackendPlugin(ABC): | |
| """Abstract base class for all backend plugins.""" | |
| def __init__(self, config_path: Path): | |
| """Initialize plugin with configuration.""" | |
| self.config = self.load_config(config_path) | |
| self.name = self.config.get('name', 'Unknown') | |
| self.version = self.config.get('version', '1.0.0') | |
| self.enabled = self.config.get('enabled', True) | |
| def health_check(self) -> bool: | |
| """Check if backend is available and healthy.""" | |
| pass | |
| def generate_image( | |
| self, | |
| prompt: str, | |
| input_images: Optional[List[Image.Image]] = None, | |
| **kwargs | |
| ) -> Image.Image: | |
| """Generate image using this backend.""" | |
| pass | |
| def get_capabilities(self) -> Dict[str, Any]: | |
| """Report backend capabilities.""" | |
| pass | |
| def load_config(self, config_path: Path) -> Dict[str, Any]: | |
| """Load plugin configuration from YAML.""" | |
| if not config_path.exists(): | |
| return {} | |
| with open(config_path) as f: | |
| return yaml.safe_load(f) or {} | |
| def __repr__(self): | |
| return f"{self.__class__.__name__}(name={self.name}, version={self.version})" | |