A web application that captures webcam input, analyzes facial expressions using Google's Gemini API, and dynamically adjusts the interface colors based on detected emotions.
- Real-time emotion detection using Google Gemini 1.5 flash model
- Dynamic UI styling based on detected emotions with color themes
- Emotion-specific content recommendations and suggestions
- In-browser webcam integration with manual and auto-capture options
- Smooth transitions between emotional states
- Debug console for troubleshooting
The application detects and responds to the following emotions:
- Happy
- Sad
- Angry
- Surprised
- Neutral
- Fearful
- Disgusted
- Python 3.8 or higher
- Google API key for Gemini Pro Vision
-
Clone this repository:
git clone <repository-url> cd emotion-reactive-app
-
Create a virtual environment and activate it:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install the required packages:
pip install -r requirements.txt
-
Set up your Google API key:
- Get a Google API key for Gemini from the Google AI Studio
- Add your API key to the
.env
file:GOOGLE_API_KEY=your_api_key_here
-
Run the Flask application:
python app.py
-
Open your browser and navigate to
http://localhost:5000
-
Click the "Start Camera" button to begin capturing webcam input
-
Click "Analyze Emotion" or toggle "Auto-Capture" to detect emotions
-
Express different emotions to see the interface change in real-time
- The application uses your browser's webcam API to capture video
- When you click "Analyze Emotion" or enable auto-capture, it:
- Captures a frame from the webcam
- Sends the image to the server as a base64-encoded JPEG
- Server processes the image with Google Gemini API to detect emotions
- Results are sent back to update the UI colors and content
emotion_reactive_app/
├── app.py # Main Flask application
├── gemini_emotion.py # Gemini API integration
├── utils.py # Helper functions
├── .env # API keys (gitignored)
├── README.md # Documentation
├── templates/ # HTML templates
│ └── index.html # Main application page
└── static/ # Static assets folder
- Browser-based webcam capture: Uses the HTML5 Webcam API for reliable camera access
- Manual and automatic capture modes: Analyze on-demand or set to auto-capture every few seconds
- Real-time UI updates: Changes colors, content, and recommendations based on detected emotions
- Built-in debugging: Visual debug console shows what's happening at each step
- Smooth visual transitions: Gradual color changes between emotional states
- Emotion detection requires good lighting conditions
- The application requires webcam access and an internet connection
- The Gemini API has rate limits and usage costs