Spaces:
Sleeping
Sleeping
| title: EmotionMirror | |
| emoji: π | |
| colorFrom: indigo | |
| colorTo: purple | |
| sdk: streamlit | |
| sdk_version: 1.26.0 | |
| app_file: app.py | |
| pinned: false | |
| # EmotionMirror | |
| EmotionMirror is an emotional analysis application that uses computer vision and AI to analyze facial expressions and body language. | |
| ## Features | |
| - **Visual Analysis**: Detect faces and analyze expressions | |
| - **Emotion Tracking**: Track emotions over time (coming soon) | |
| - **Multi-Agent System**: Coordinated analysis with specialized agents | |
| - **Group Analysis**: Process images with multiple faces (up to 5), with mandatory face labeling | |
| - **Comprehensive History**: View both group analyses and individual analyses from group photos | |
| - **Hugging Face Integration**: Designed for deployment on Hugging Face Spaces | |
| ## Project Structure | |
| ``` | |
| EmotionMirror/ | |
| βββ app.py # Main Streamlit application | |
| βββ config/ # Configuration | |
| β βββ __init__.py | |
| β βββ settings.py # Centralized settings | |
| βββ agent_framework/ # Agent implementation | |
| β βββ __init__.py | |
| β βββ base_agent.py # Base agent class | |
| β βββ visual_agent.py # Visual processing agent | |
| β βββ agent_manager.py # Agent coordinator | |
| βββ services/ # Modular services | |
| β βββ __init__.py | |
| β βββ model_service.py # Model management service | |
| βββ utils/ # Utilities | |
| β βββ __init__.py | |
| β βββ file_utils.py # File handling utilities | |
| βββ models/ # Pre-trained models | |
| βββ static/ # Static assets | |
| βββ uploads/ # Uploaded images | |
| βββ results/ # Processing results | |
| ``` | |
| ## Requirements | |
| - Python 3.9+ | |
| - Streamlit | |
| - Ultralytics YOLO | |
| - OpenCV | |
| - Torch | |
| - See requirements.txt for complete list | |
| ## Installation | |
| 1. Clone the repository | |
| 2. Install dependencies: | |
| ``` | |
| pip install -r requirements.txt | |
| ``` | |
| 3. Run the application: | |
| ``` | |
| streamlit run app.py | |
| ``` | |
| ## Deployment to Hugging Face Spaces | |
| This application is designed to be deployed on Hugging Face Spaces. To deploy: | |
| 1. Push this repository to GitHub | |
| 2. Create a new Space on Hugging Face | |
| 3. Connect your GitHub repository | |
| 4. Set the Space SDK to "Streamlit" | |
| 5. The application will automatically deploy | |
| ## Development Roadmap | |
| - **Phase 1**: Basic visual analysis with YOLO | |
| - **Phase 2**: Database integration for emotion tracking | |
| - **Phase 3**: Hume.ai integration and advanced multi-agent system | |
| ## Recent Changes to Analysis History | |
| ### Group Analysis Update (April 2025) | |
| The Group Analysis and History functionality have been enhanced with several important improvements: | |
| #### 1. Group Size Limitation | |
| - **Updated Limit**: Group analysis is now limited to a maximum of 5 faces per image | |
| - **Improved Performance**: This change improves processing speed and UI responsiveness | |
| - **Clear User Feedback**: Warning messages clearly inform users when images exceed the limit | |
| #### 2. Mandatory Face Labeling | |
| - **Required Fields**: All selected faces in group analysis now require name labels | |
| - **Validation System**: Prevents saving analyses with incomplete labeling | |
| - **Visual Indicators**: Warning messages appear next to empty name fields | |
| - **Enhanced UI**: Improved face cropping for clearer identification during labeling | |
| #### 3. Comprehensive Analysis History | |
| - **Dual Analysis Storage**: Group photos now generate both: | |
| - One group analysis with aggregate statistics | |
| - Individual analyses for each labeled person in the photo | |
| - **Enhanced Filtering**: Filter history by person name across all analyses | |
| - **Improved Navigation**: Clear separation between individual and group analyses | |
| ### Synchronization Update (April 2025) | |
| The Analysis History functionality has been completely synchronized between the local and Hugging Face versions to ensure consistent behavior. Below are the key improvements: | |
| #### 1. Tab Structure Enhancement | |
| - Added the "Statistics" tab between "Recent Analyses" and "Export Data" | |
| - Implemented clear sequential numbering (1, 2, 3...) for all sections | |
| #### 2. Person Filtering System | |
| - Fixed the person tag system to properly save and display person names | |
| - Implemented dropdown filtering by person name across all History tabs | |
| - Corrected tag saving to use actual person names instead of emotion labels | |
| #### 3. Export Functionality Expansion | |
| - Added "Current Session" vs "All Sessions" filtering options | |
| - Implemented adjustable record limit for exports | |
| - Enhanced person filtering for export data | |
| #### 4. Data Visualization Improvements | |
| - Improved record display with expandable sections | |
| - Enhanced chart visualization for emotion distributions | |
| - Added detailed display of advanced data (age, gender) when available | |
| ### UI Architecture Improvements (Late April 2025) | |
| Several significant technical improvements have been implemented to enhance the robustness and maintainability of the application: | |
| #### 1. Modular Architecture | |
| - **Complete Refactoring**: Application has been reorganized into controllers, services, and utility modules | |
| - **Dependency Injection**: Services now receive configuration rather than hardcoding it | |
| - **Separation of Concerns**: UI logic, business logic, and data access have been separated | |
| #### 2. Streamlit Column Nesting Fix | |
| - **Problem Solved**: Fixed the Streamlit limitation that only allows one level of column nesting | |
| - **Enhanced UI Components**: Redesigned UI elements using tabs and flat layouts instead of nested columns | |
| - **Tab-Based Navigation**: Implemented tabs for content organization to avoid excessive column usage | |
| #### 3. False Positive Detection | |
| - **Detection Validation**: Added checks to warn users about potential false positives in face detection | |
| - **Confidence Thresholds**: Clear warnings when detected faces have low confidence scores | |
| - **Size Validation**: Alerts for unusually small or large detected face regions | |
| #### 4. Static Asset Management | |
| - **Robust Directory Creation**: Automatic creation of required directories like "static/" and "static/results/" | |
| - **Image Fallbacks**: Graceful handling of missing images with base64 backups | |
| - **Platform Compatibility**: Consistent path handling across both local and Hugging Face environments | |
| ### Technical Details | |
| The Hugging Face version previously handled tags differently from the local version. This has been corrected to ensure complete consistency: | |
| - **Old Method (Fixed)**: Saved generic tags like 'emotion_analysis' and emotion names | |
| - **New Method**: Uses the person's name as the sole tag, identical to local version | |
| This ensures that filters now show actual person names rather than emotion categories, making it easier to track analyses by individual. | |
| ### Additional Debugging | |
| The Hugging Face version includes extra debugging statements to help troubleshoot database operations, especially for tag handling and record retrieval, which are particularly important given the platform's permission restrictions. | |
| ## License | |
| This project is licensed under the MIT License - see the LICENSE file for details. | |
| ## Additional Information | |
| ### EmotionMirror - Facial Emotion Analysis with Computer Vision | |
| EmotionMirror is an emotional analysis application based on computer vision that uses artificial intelligence models to detect and analyze emotions from facial expressions. | |
| ### Features | |
| - **Facial Analysis**: Detection of faces and recognition of basic emotions | |
| - **Results Visualization**: Clear presentation of data with numbered and sequential text | |
| - **Intuitive Interface**: Minimalist design with well-defined sections | |
| - **Group Analysis**: Process group photos with up to 5 people | |
| - **Mandatory Labeling**: All faces in group photos must be labeled with names | |
| - **Comprehensive History**: View both group analyses and individual analyses from group photos | |
| ### Technologies | |
| - Streamlit for the user interface | |
| - YOLOv8 for facial detection and pose analysis | |
| - Custom agent framework for analysis coordination | |
| - DeepFace for advanced emotion detection (when enabled) | |
| ### Usage | |
| 1. Navigate to the "Visual Analysis" page | |
| 2. Upload an image containing faces | |
| 3. Click on "Detect Faces in Image" | |
| 4. For single face images: | |
| - Enter the person's name | |
| - Click "Analyze Individual" | |
| 5. For group images (2-5 faces): | |
| - Select which faces to analyze using the checkboxes | |
| - Provide names for each selected face (mandatory) | |
| - Enter a group name | |
| - Click "Save Group Analysis" | |
| 6. View analysis results in the History page, which includes: | |
| - Individual analyses (both from single photos and group photos) | |
| - Group analyses with aggregate statistics | |
| ### Version Notes | |
| Current version: 0.1.3 (Phase 1.3 - April 2025) | |
| - Basic facial detection implementation | |
| - Functional Streamlit user interface | |
| - Basic emotion classification | |
| - Group analysis with up to 5 people | |
| - Mandatory face labeling system | |
| - Improved history display showing both group and individual analyses | |