Skip to content

KTB2110/DJ_Assistant_RecommendationEngine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

8 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŽง DJ Assistant

An intelligent DJ assistant that recommends tracks based on harmonic compatibility, BPM matching, and energy flow โ€” using real DJ mixing principles.

Try it out

Python FastAPI React Tailwind CSS

Note: Song recommendations are currently limited to the ~90,000 tracks in the Maharishi Dataset from Hugging Face.


โœจ Features

๐ŸŽน Harmonic Mixing (Camelot Wheel)

  • Automatically maps Spotify key/mode data to the Camelot Wheel notation (1A-12A, 1B-12B)
  • Recommends tracks that are harmonically compatible for smooth transitions
  • Supports same key, relative key, and adjacent key matching with configurable thresholds

๐ŸŽš๏ธ BPM Compatibility

  • Intelligent tempo matching with configurable tolerance (default ยฑ7%)
  • Half-time/double-time detection โ€” seamlessly mix 70 BPM with 140 BPM tracks
  • Direction controls: faster, maintain, or slower for building or dropping energy

โšก Energy Flow Management

  • Control the energy trajectory of your set with build, maintain, or drop modes
  • Separate control for energy levels independent of other audio features
  • Smart scoring that accounts for edge cases (can't build when already at max)

๐ŸŽ›๏ธ Advanced Audio Feature Controls

Fine-tune recommendations using Spotify's audio analysis features:

Feature Description
Danceability How suitable for dancing (rhythm, tempo, beat strength)
Valence Musical positiveness (happy vs sad)
Acousticness Likelihood of being acoustic
Instrumentalness Predicts if track has no vocals
Speechiness Presence of spoken words
Liveness Presence of live audience
Loudness Overall loudness in dB

Each feature supports directional control: build, maintain, or drop.

๐ŸŽธ Genre Intelligence

  • Genre similarity engine using audio feature centroids
  • Automatically suggests similar genres based on your current track
  • Explainable results: "Similar energy (0.78 vs 0.81) and tempo (128 vs 126 BPM)"
  • Filter recommendations by specific genres

๐ŸŽš๏ธ Dual Deck System

  • Deck A & Deck B for professional DJ-style workflow
  • Build separate playlists for each deck
  • Toggle recommendation source between decks
  • Preview tracks before committing to your set

๐Ÿ—๏ธ Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                      Frontend (React + Vite)                     โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚   Deck A    โ”‚  โ”‚   Deck B    โ”‚  โ”‚    Recommendations      โ”‚  โ”‚
โ”‚  โ”‚  (Preview)  โ”‚  โ”‚  (Preview)  โ”‚  โ”‚  (Scored & Filtered)    โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                              โ”‚
                              โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                     FastAPI Backend (api.py)                     โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚   /search   โ”‚  โ”‚  /recommend โ”‚  โ”‚  /genres/{genre}/similarโ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                              โ”‚
                              โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                        Core Engine (src/)                        โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚  Camelot    โ”‚  โ”‚   Scoring   โ”‚  โ”‚    Genre Similarity     โ”‚  โ”‚
โ”‚  โ”‚   Wheel     โ”‚  โ”‚   Engine    โ”‚  โ”‚    (Euclidean dist)     โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
โ”‚  โ”‚ Recommender โ”‚  โ”‚        TrackDatabase (HuggingFace)      โ”‚   โ”‚
โ”‚  โ”‚   Engine    โ”‚  โ”‚        114k+ Spotify Tracks             โ”‚   โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿš€ Quick Start

Prerequisites

  • Python 3.10+
  • Node.js 18+ (for frontend)

1. Clone & Setup Backend

git clone https://github.com/KTB2110/dj-assistant.git
cd dj-assistant

# Create virtual environment
python -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

# Set up environment variables (for Spotify API features)
cp .env.example .env
# Edit .env with your Spotify API credentials

2. Start the API Server

uvicorn api:app --reload

The API will be available at http://127.0.0.1:8000

3. Setup & Run Frontend

cd frontend
npm install
npm run dev

The frontend will be available at http://localhost:5173


๐Ÿ“ก API Reference

Search Tracks

GET /search?query=daft+punk&limit=10

Get Track by ID

GET /track/{track_id}

Get Recommendations

POST /recommend
Content-Type: application/json

{
  "track": { ... },           // Current track object
  "bpm_direction": "maintain", // "faster" | "maintain" | "slower"
  "energy_direction": "build", // "build" | "maintain" | "drop"
  "feature_directions": {      // Optional advanced controls
    "danceability": "maintain",
    "valence": "build",
    "loudness": "drop"
  },
  "limit": 10,
  "genre_filter": ["house", "tech-house"],
  "camelot_threshold": 0.7
}

Get All Genres

GET /genres

Get Similar Genres

GET /genres/{genre}/similar?top_k=10

๐Ÿ“ Project Structure

dj-assistant/
โ”œโ”€โ”€ api.py                    # FastAPI backend server
โ”œโ”€โ”€ app.py                    # Streamlit app (alternative UI)
โ”œโ”€โ”€ requirements.txt          # Python dependencies
โ”‚
โ”œโ”€โ”€ src/                      # Core Python modules
โ”‚   โ”œโ”€โ”€ camelot.py            # Camelot wheel & harmonic mixing
โ”‚   โ”œโ”€โ”€ scoring.py            # BPM, energy, loudness compatibility
โ”‚   โ”œโ”€โ”€ recommender.py        # Main DJRecommender engine
โ”‚   โ”œโ”€โ”€ database.py           # Track database (HuggingFace dataset)
โ”‚   โ”œโ”€โ”€ genres.py             # Genre similarity engine
โ”‚   โ””โ”€โ”€ config.py             # Configuration & environment
โ”‚
โ”œโ”€โ”€ frontend/                 # React + Vite frontend
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ App.jsx           # Main dual-deck interface
โ”‚   โ”‚   โ””โ”€โ”€ ...
โ”‚   โ”œโ”€โ”€ package.json
โ”‚   โ””โ”€โ”€ vite.config.js
โ”‚
โ”œโ”€โ”€ notebooks/                # Jupyter notebooks for exploration
โ”‚   โ”œโ”€โ”€ genre_analysis.ipynb  # Genre similarity development
โ”‚   โ””โ”€โ”€ spotipy_analysis.ipynb
โ”‚
โ”œโ”€โ”€ data/                     # Data files
โ”‚   โ”œโ”€โ”€ raw/
โ”‚   โ”œโ”€โ”€ processed/
โ”‚   โ””โ”€โ”€ cache/
โ”‚
โ””โ”€โ”€ tests/                    # Unit tests
    โ”œโ”€โ”€ test_recommender.py
    โ”œโ”€โ”€ test_dataset.py
    โ””โ”€โ”€ ...

๐Ÿงฎ Scoring Algorithm

The recommendation engine uses a weighted scoring system:

Default Weights

Component Weight Description
BPM 35% Tempo compatibility
Energy 35% Energy level match
Features 30% Audio feature similarity

Advanced Mode Weights

When custom feature weights are applied:

Component Weight
BPM 27.5%
Energy 27.5%
Features 45%

Camelot Similarity Scores

Relationship Score
Same key 1.0
Relative key (same number, Aโ†”B) 0.95
Adjacent key (ยฑ1, same mode) 0.85
Adjacent key (ยฑ1, different mode) 0.75
2 steps apart 0.5
3-4 steps apart 0.25
5+ steps apart 0.1

๐Ÿ”ง Configuration

Environment Variables

Create a .env file in the root directory:

SPOTIFY_CLIENT_ID=your_client_id
SPOTIFY_CLIENT_SECRET=your_client_secret

Customizing Weights

You can customize the scoring weights when calling the recommender:

from src.recommender import DJRecommender

recommender.recommend(
    current_track=track,
    master_weights={
        'bpm': 0.4,
        'energy': 0.4,
        'features': 0.2
    },
    feature_weights={
        'danceability': 1.5,  # Prioritize danceability
        'valence': 0.5,       # De-prioritize mood
    }
)

๐Ÿงช Running Tests

pytest tests/ -v

๐Ÿ›ฃ๏ธ Roadmap

  • Spotify OAuth integration for library access
  • Audio preview playback
  • Setlist export (M3U, CSV)
  • BPM/key analysis for local files
  • Transition suggestions between tracks
  • Machine learning personalization

๐Ÿ“„ License

MIT License โ€” feel free to use this for your own DJ projects!


๐Ÿ™ Acknowledgments


Built with โค๏ธ for DJs who love data

About

Recommendation Engine to help DJs select songs based off of what they are already playing

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors