""" UI Controller Module for EmotionMirror application. This module contains the UIController class that manages the user interface components and interactions throughout the application. """ import streamlit as st import logging from typing import Dict, Any, Optional import numpy as np from PIL import Image import io import os from datetime import datetime from services.image_service import ImageService from services.database_service import DatabaseService class UIController: """ Controller for managing the user interface components of the application. Handles the setup and display of UI elements throughout the app. """ def __init__( self, image_service: Optional[ImageService] = None, database_service: Optional[DatabaseService] = None, config: Optional[Dict[str, Any]] = None ): """ Initialize the UI controller with optional service dependencies. Args: image_service: Optional ImageService instance for image processing database_service: Optional service for database operations config: Optional configuration dictionary with app settings """ self.image_service = image_service or ImageService() self.database_service = database_service or DatabaseService() self.config = config or {} def setup_image_upload_interface(self): """ Set up and display the image upload interface with validation feedback. Returns: The uploaded file object if an image was successfully uploaded and validated """ # Create file uploader uploaded_file = st.file_uploader( "Choose an image...", type=["jpg", "jpeg", "png"], help="Upload a clear image of a face for analysis." ) if uploaded_file is not None: # Validate image file validation_result = self.image_service.validate_image_file( uploaded_file, check_content=True, check_dimensions=True ) # If validation failed, show issues if not validation_result["valid"]: st.error("Image validation failed:") for issue in validation_result["issues"]: st.warning(issue) return None return uploaded_file