""" Image Context Model for EmotionMirror application. This module defines the ImageContext class that represents an image analysis context including metadata and results. """ from typing import Dict, Any, List, Optional from datetime import datetime class ImageContext: """ Represents an image context for analysis including metadata and results. """ def __init__( self, image_id: str, timestamp: Optional[datetime] = None, metadata: Optional[Dict[str, Any]] = None, faces: Optional[List[Dict[str, Any]]] = None ): """ Initialize an image context. Args: image_id: Unique identifier for the image timestamp: Time when the image was processed metadata: Image metadata like dimensions, format, etc. faces: List of detected faces and their analysis """ self.image_id = image_id self.timestamp = timestamp or datetime.now() self.metadata = metadata or {} self.faces = faces or [] def to_dict(self) -> Dict[str, Any]: """ Convert the image context to a dictionary for storage or serialization. Returns: Dictionary representation of the image context """ return { "image_id": self.image_id, "timestamp": self.timestamp.isoformat(), "metadata": self.metadata, "faces": self.faces } @classmethod def from_dict(cls, data: Dict[str, Any]) -> 'ImageContext': """ Create an image context from a dictionary. Args: data: Dictionary with image context data Returns: An ImageContext instance """ return cls( image_id=data.get("image_id", ""), timestamp=datetime.fromisoformat(data.get("timestamp", datetime.now().isoformat())), metadata=data.get("metadata", {}), faces=data.get("faces", []) )