Webcam → YOLO person detection → DeepFace emotions → hype score → auto Spotify playlist switch + Hue lights + live dashboard.
Webcam → VisionProcessor (thread) → EmotionCache → DJBrain → Spotify / Lights
↓
FastAPI /ws → React UI
FastAPI /video_feed (MJPEG)
- Python 3.10+
- Node.js 18+
- A webcam
- (Optional) Active Spotify Premium account + Spotify app
- (Optional) Philips Hue bridge
cd ai-dj/backend
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txtNote: DeepFace downloads ~500 MB of face models on first run. This is normal — wait for the download to complete before expecting emotion labels.
Copy .env.example to .env and fill in values:
cp .env.example .env| Variable | Required | Description |
|---|---|---|
SPOTIPY_CLIENT_ID |
Spotify only | From Spotify Developer Dashboard |
SPOTIPY_CLIENT_SECRET |
Spotify only | From Spotify Developer Dashboard |
SPOTIPY_REDIRECT_URI |
Spotify only | Must match app settings (default: http://localhost:8888/callback) |
HUE_BRIDGE_IP |
Hue only | Leave blank for mock lights (prints to console) |
HUE_USERNAME |
Hue only | Hue API username (see Hue setup below) |
WEBCAM_INDEX |
No | Webcam device index (default: 0) |
- Go to https://developer.spotify.com/dashboard
- Create an app
- Add
http://localhost:8888/callbackas a Redirect URI - Copy Client ID and Client Secret to
.env - Open Spotify on any device and start playing something (so there's an active device)
- On first run, a browser window will open for OAuth. Complete the login.
- Replace the
REPLACE_WITH_*_URIplaylist constants inconfig.pywith your own Spotify playlist URIs (right-click playlist → Share → Copy Spotify URI)
# Find your bridge IP
python -c "from phue import PhueRegistrationException; from phue import Bridge; b = Bridge('YOUR_BRIDGE_IP'); b.connect()"Press the button on your Hue bridge when prompted, then copy the username printed to .env.
Leave HUE_BRIDGE_IP blank to use MockLightController (prints color/brightness to console).
cd ai-dj/frontend
npm installcd ai-dj/backend
source .venv/bin/activate
uvicorn main:app --reloadcd ai-dj/frontend
npm run devOpen http://localhost:5173 in a browser.
No webcam / wrong camera
- Set
WEBCAM_INDEX=1(or 2, 3…) in.envto try other cameras - On macOS/Linux, run
ls /dev/video*to list devices
DeepFace first-run model download
- Wait 2–5 minutes on first start — it downloads VGG-Face and other model weights
- If it hangs, check your internet connection; models are cached in
~/.deepface/
"No active Spotify device" warning
- Open Spotify (app or web player) and play any track to create an active session
- The backend will continue without Spotify — music just won't change
Backend crashes on startup
- Check Python version:
python --version(need 3.10+) - Ensure all packages installed:
pip install -r requirements.txt
Frontend shows "CONNECTING…"
- Make sure the backend is running:
uvicorn main:app --reload - Check CORS — both must run on localhost
Hue lights not responding
- Verify bridge IP with:
python -c "from phue import Bridge; b = Bridge('IP'); b.connect()" - Press bridge button before connecting for the first time