Spotify Music Recommendation System

A machine learning-powered music recommendation system built with FastAPI and Streamlit, utilizing the Spotify API for music data and recommendations.

Project Overview

This project demonstrates a complete music recommendation system that leverages the Spotify Web API and machine learning techniques to provide personalized music recommendations to users.

By analyzing audio features of tracks and user preferences, the system can suggest new music that aligns with the user's taste while introducing them to tracks they might not discover otherwise.

Spotify Recommendation System Demo

Demo of the Spotify Recommendation System in action

Key Features
  • User authentication and registration
  • Personalized music recommendations
  • Track audio feature analysis
  • User preference tracking
  • Interactive web interface
  • Real-time music recommendations

Tech Stack

Backend

FastAPI: Modern, high-performance web framework for building APIs with Python

SQLAlchemy: SQL toolkit and Object-Relational Mapping (ORM) library

Pydantic: Data validation and settings management using Python type annotations

Frontend & Data

Streamlit: Open-source app framework for Machine Learning and Data Science

Pandas/NumPy: Data manipulation and analysis tools

Plotly: Interactive data visualization library

Infrastructure

SQLite: Lightweight disk-based database

JWT: JSON Web Tokens for secure authentication

Spotify Web API: Access to Spotify's music catalog and user data

Installation & Setup

Stage 1: Clone Repository

Get the code from GitHub and navigate to the project directory.

git clone https://github.com/yourusername/spotify-recommendation-system.git
cd spotify-recommendation-system

Stage 2: Environment Setup

Create and activate a virtual environment for the project.

conda create -n env python=3.8+
conda activate env

Stage 3: Install Dependencies

Install all required packages using pip.

pip install -r requirements.txt

Stage 4: Configure Environment Variables

Create a .env file in the root directory with your Spotify API credentials.

SPOTIFY_CLIENT_ID=your_client_id_here
SPOTIFY_CLIENT_SECRET=your_client_secret_here
DATABASE_URL=sqlite:///./spotify_recommender.db
SECRET_KEY=your_secret_key_here

Running the Application

Backend (FastAPI)

Start the FastAPI backend server with the following command:

uvicorn app.main:app --reload

Access the API documentation at http://localhost:8000/docs

Frontend (Streamlit)

In a new terminal, start the Streamlit frontend:

streamlit run streamlit_app.py

Access the web interface at http://localhost:8501

Usage Guide

Step-by-Step Instructions
Step 1: Registration

Register a new account using the registration form. Provide a username, email, and secure password.

Step 2: Login

Log in with your credentials to access the recommendation system features.

Step 3: Find Track IDs

You can get track IDs from Spotify by right-clicking a song and selecting "Share > Copy Spotify URI". The track ID is the string after "spotify:track:".

Step 4: Get Recommendations

Enter a Spotify track ID to get personalized recommendations based on that seed track.

Step 5: Rate Recommendations

View the recommended tracks and provide feedback to improve future recommendations.

Development Components

API & Data Layer
  • API development: FastAPI endpoints in app/routers/
  • Database models: SQLAlchemy models in app/models/
  • Business logic: Services in app/services/
Frontend & User Experience
  • Interface: Streamlit components in streamlit_app.py
  • Data visualizations: Interactive charts for audio features
  • User profiles: Tracking preferences over time