An end-to-end Agentic AI Music Recommendation & Chatbot system that uses FastAPI, LangGraph stateful conversation workflows, Spotify/iTunes API integrations, and a hybrid content-based recommendation engine.
#recommender-system #fastapi #langgraph #spotify-api #machine-learning #chatbot #vanilla-js #python-313 #ai-music-assistant #agentic-ai #content-based-filtering #docker #sqlite3 #glassmorphism #web-audio-api
This project evolves from a basic university song recommender into a production-grade conversational agent. It simulates a real-world cognitive music assistant capable of:
- Stateful multi-turn conversational chat
- Music preference extraction & refinement using LLMs
- External API catalog ingestion (Spotify & iTunes Search integration)
- Free keyless fallback for instant real-world track retrieval
- Hybrid content-based scoring (TF-IDF + Cosine Similarity)
- Dynamic UX analysis (Valence, Danceability, Energy metrics)
- Session-based user feedback loops (Like / Dislike personalization)
- Production-ready Docker containerization
- LangGraph: Stateful multi-turn conversation orchestrator
- Gemini AI / OpenAI / Anthropic: Structured preference extraction
- Pydantic v2: Response schemas and settings validation
- Scikit-learn: Cosine similarity & MinMaxScaler
- Pandas & NumPy: Ingest, clean, and score datasets
- External APIs: Spotify Web API (spotipy) & iTunes Search API
- FastAPI: High-performance async REST API
- SQLAlchemy 2.x: Async database interactions (SQLite)
- Uvicorn: ASGI web server
- Vanilla HTML5 & CSS3: Sleek "Classic Champagne & Gold" glassmorphic UI
- Vanilla JavaScript: Real-time web audio, metrics aggregation, state management
- Docker & Docker Compose: Containerization
- Pytest: Integration and unit testing suite
The system supports two catalog modes:
- Curated In-Memory Catalog:
- Source:
backend/data/songs.csv - Generated using a custom dataset builder containing 204 highly diverse pop, lofi, hip-hop, classical, rock, Bollywood, and Punjabi songs.
- Source:
- Global Real-World API Catalog:
- Instantly fetches tracks from the Spotify Web API or iTunes API (over 100M songs, real artwork, and 30-second preview streams).
Standard recommendation algorithms suffer from cold-start problems and rigid keyword search. Traditional chat interfaces do not capture nuanced user preferences or explain why songs were matched.
This project solves this by:
- Leveraging stateful agents to extract implicit mood, tempo, and language preferences.
- Dynamically mapping user conversational intent to acoustic metrics (Valence, Energy, Acousticness).
- Combining real-time user session likes/dislikes directly into the scoring formula.
- Generating rich LLM explanations for each recommended song.
Chatbot-Song-Recommender-System/
│
├── backend/
│ ├── app/
│ │ ├── ai/ # Intent classification, prompts, LangGraph workflow
│ │ ├── api/v1/ # Endpoints (chat, songs, feedback)
│ │ ├── core/ # Configuration settings
│ │ ├── db/ # Database session management
│ │ ├── models/ # SQLAlchemy ORM and Pydantic schemas
│ │ ├── recommender/ # Cosine ranking, exploration jitter, Spotify/iTunes API
│ │ │ ├── engine.py
│ │ │ └── external_provider.py
│ │ ├── services/ # Business logic orchestrators
│ │ └── main.py # FastAPI App root
│ │
│ ├── data/
│ │ └── songs.csv # Seed song catalog
│ │
│ ├── scripts/
│ │ └── generate_sample_data.py
│ │
│ ├── tests/ # Pytest unit and integration test suite
│ │ ├── integration/
│ │ └── unit/
│ │
│ ├── Dockerfile
│ ├── pyproject.toml
│ └── requirements.txt
│
├── docs/
│ └── project_report.md # Full university report compilation
│
├── frontend/
│ ├── static/
│ │ ├── css/
│ │ │ └── styles.css # "Champagne & Gold" theme rules
│ │ └── js/
│ │ └── app.js # Chat and metrics visualization logic
│ └── index.html # Main workspace dashboard
│
├── docker-compose.yml
├── README.md
└── .gitignore- LangGraph Cognitive Flow: Intent classification, extraction, retrieve candidates, rank, explain, and respond.
- Spotify / iTunes Dual Ingestion: Real-time API query that resolves track details, covers, and audio preview links.
- Dynamic Taste Profile Dashboard: Client-side aggregation and animation of the recommendations' acoustic metadata.
- Interactive Gold Filters: Country (India/International), language, and genre filtering dropdowns.
- Onboarding Quick-Pills: Instant clickable prompts for first-time visitors.
- Hermetic Fallbacks: Fallback to local files if offline; bypass external APIs during tests.
- Exploration Jitter: Stochastic ranking diversity prevents deterministic recommendation loops.
User Query
│
▼
LangGraph Agent
│
(Extract Preferences)
│
├──► Spotify API (If configured) ───┐
│ ├─► Ingest Real Tracks
├──► iTunes API (Keyless Fallback) ──┘
│
▼
Local TF-IDF Catalog (Backup)
│
▼
Scoring Engine (Mood + Popularity + Feedback)
│
▼
Exploration Jitter (Diversity Variance)
│
▼
LangGraph Explanation Generator (LLM reasons)
│
▼
Visual Taste Dashboard & Gold Cards Grid
git clone https://github.com/yogsgehlot/Chatbot-Song-Recommender-System
cd Chatbot-Song-Recommender-Systempython -m venv .venv
.venv\Scripts\activatepython3 -m venv .venv
source .venv/bin/activatecd backend
pip install -r requirements.txtpython scripts/generate_sample_data.pyCreate a .env file in the backend/ directory:
cp .env.example .envOpen .env and fill in your keys:
# LLM Configuration
GEMINI_API_KEY=your-gemini-api-key-here
# Spotify Credentials (Optional - Falls back to keyless iTunes API if empty)
SPOTIFY_CLIENT_ID=your-spotify-client-id
SPOTIFY_CLIENT_SECRET=your-spotify-client-secretuvicorn app.main:app --reload --port 8000pytest tests/ -vOpen:
http://127.0.0.1:8000/docs
Handles conversational messages, extracts preferences, and returns matched recommendations.
{
"message": "Give me some high energy hip hop tracks",
"session_id": "session-1234"
}{
"session_id": "session-1234",
"message": "Here are 5 high-energy hip-hop tracks to get you moving!",
"intent": "recommendation",
"recommendations": [
{
"song": {
"id": "it_1440854444",
"title": "HUMBLE.",
"artist": "Kendrick Lamar",
"album": "DAMN.",
"genre": "hip-hop",
"language": "english",
"year": 2017,
"energy": 0.81,
"valence": 0.42,
"tempo": 150.0,
"danceability": 0.90,
"acousticness": 0.01,
"preview_url": "https://audio-ssl.itunes.apple.com/.../preview.mp3",
"cover_url": "https://is1-ssl.mzstatic.com/image/thumb/...",
"popularity": 85
},
"score": 0.942,
"reasons": [
"Matches high energy requests",
"Classic Kendrick Lamar hip-hop beat"
],
"rank": 1
}
]
}Submits session feedback to bias future recommendations.
{
"song_id": "it_1440854444",
"session_id": "session-1234",
"feedback_type": "like"
}docker-compose up --build- Vector Search Database: Ingesting FAISS/Milvus for hybrid embedding semantic song search.
- Multi-User Profiles: Persistent database schemas with OAuth2 login.
- Audio-Wave Visualizations: Real-time canvas representation of played music.
- Auto-Generated Playlists: Exporting curated recommended songs directly to users' Spotify accounts.
- Designed Stateful AI Agent: Built multi-turn music assistant utilizing LangGraph state machines, reducing conversational failure rates by handling refinements seamlessly.
- Engineered Dual API Ingestion System: Constructed an external provider layer merging Spotify API with an iTunes Search API fallback to deliver real-world songs, cover art, and preview audios.
- Implemented Custom Hybrid Recommender: Formulated a content-based indexing and scoring pipeline combining TF-IDF, Cosine Similarity, and dynamic session-based liked-song weights.
- Constructed High-End UI/UX Dashboard: Designed a glassmorphic dashboard showcasing real-time animated acoustic taste parameters (Valence, Energy, etc.).
- Stateful conversational workflows (LangGraph).
- Audio feature mapping and recommendation models.
- Dynamic client-side API metric aggregation.
- Fallback and credential management practices.
- Hermetic API mock testing practices in python (
pytest).
Yogesh Gehlot
AI/ML Engineer | Backend Developer
- GitHub: yogsgehlot
- LinkedIn: Yogesh Gehlot
- X: @yogsgehlot
This project is for educational and portfolio purposes.