https://github.com/extractoro/mood-2-mix
Emotion-Based Playlist Generator
https://github.com/extractoro/mood-2-mix
Last synced: 5 months ago
JSON representation
Emotion-Based Playlist Generator
- Host: GitHub
- URL: https://github.com/extractoro/mood-2-mix
- Owner: Extractoro
- Created: 2025-06-18T06:54:22.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-06-29T09:52:28.000Z (12 months ago)
- Last Synced: 2025-07-08T05:05:00.953Z (12 months ago)
- Language: Python
- Size: 25.4 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Mood2Mix π§
Full-stack FastAPI-based service that analyzes the userβs emotional prompt using GPT and recommends music tracks accordingly. It integrates with YouTube Music and Spotify to recommend or create playlists, using OpenAI, ytmusicapi, and Spotify Web API. Async-ready, Dockerized, and structured for scalability.
## Table of Contents
* [β¨ Features](#-features)
* [π Project Structure](#-project-structure)
* [βοΈ Getting Started](#-getting-started)
* [1. Clone the Repository](#1-clone-the-repository)
* [2. Configure Environment](#2-configure-environment)
* [3. Run with Docker](#3-run-with-docker)
* [π§ͺ Testing](#-testing)
* [π API Endpoints](#-api-endpoints)
* [π Mood Analysis](#-mood-analysis)
* [π΅ Recommendations](#-recommendations)
* [π§ Spotify Integration](#-spotify-integration)
* [π Interactive Docs](#-interactive-docs)
## β¨ Features
* π Analyze free-form emotional text using OpenAI (GPT-4o)
* π Extract mood, valence, energy, genres, and a music query
* πΆ Recommend music from YouTube Music and/or Spotify
* π§ GPT-based intelligent search query generation
* β
Async FastAPI backend with exception handling
* π§ Spotify playlist creation & track addition support
* π Dockerized environment
* π OAuth 2.0 authentication for Spotify
* π Swagger + ReDoc interactive documentation
## π Project Structure
```
πΉ gpt/
πΉ βββ mood_analyzer.py # GPT prompt logic
πΉ music_providers/
πΉ βββ base.py # Abstract music provider
πΉ βββ spotify.py # Spotify integration
πΉ βββ ytmusic.py # YouTube Music integration
πΉ routes/
πΉ βββ mood.py # Mood analysis routes
πΉ βββ recommend.py # Song recommendation endpoint
πΉ βββ spotify.py # Spotify-related endpoints
πΉ utils/
πΉ βββ get_spotify_token_from_header.py # Extract Bearer token
πΉ βββ spotify_list_ids.py # Map tracks to Spotify URIs
πΉ schemas/
πΉ βββ schemas.py # Pydantic models
πΉ βββ enums.py # Enum for music providers
πΉ .env
πΉ docker-compose.yml
πΉ Dockerfile
πΉ README.md
```
## βοΈ Getting Started
### 1. Clone the Repository
```bash
git clone https://github.com/Extractoro/mood-2-mix.git
cd mood2mix
```
### 2. Configure Environment
Create a `.env` file:
```
OPENAI_API_KEY=your_openai_key
SPOTIFY_CLIENT_ID=your_client_id
SPOTIFY_CLIENT_SECRET=your_client_secret
SPOTIFY_USER_ID=your_user_id
REDIRECT_URI=http://127.0.0.1:8000/callback
```
### 3. Run with Docker
```bash
docker-compose up --build
```
## π§ͺ Testing
```bash
pytest/tests
flake8 .
```
## π API Endpoints
### π Mood Analysis
| Method | Endpoint | Description |
| ------ | --------------------------- | ------------------------------- |
| POST | /mood/analyze | Analyze emotional text |
| POST | /mood/analyze-and-recommend | Analyze and get recommendations |
### π΅ Recommendations
| Method | Endpoint | Description |
| ------ | ---------------- | ------------------------------ |
| POST | /recommend/songs | Recommend songs from mood data |
### π§ Spotify Integration
| Method | Endpoint | Description |
| ------ | ------------------------------ | ------------------------------------- |
| GET | /spotify/auth/link | Get Spotify auth URL |
| GET | /spotify/callback | Exchange code for token |
| POST | /spotify/create-playlist | Create a new playlist |
| POST | /spotify/{playlist\_id}/tracks | Add tracks to a playlist |
| POST | /spotify/prompt-to-playlist | Full flow: prompt β tracks β playlist |
## Moods examples
### π§ Example 1: Neutral, relaxing
> It was just an ordinary day. I had some coffee, did a bit of work, and enjoyed the quiet. No rush, no noise.
---
### π΅ Example 2: Happy, uplifting
> Finally finished the project! It feels like a huge weight has been lifted. Iβm so full of energy β I could jump for joy!
---
### π§ Example 3: Sad, melancholic
> Everything feels so empty. Itβs been raining all day, and my thoughts keep driftingβ¦ I feel kind of lost.
---
### π Example 4: Frustrated, tense
> Iβm so fed up! These constant crashes and deadlines are driving me crazy. I just canβt deal with this mess anymore.
---
### π Example 5: Calm, peaceful
> I sat by the window with a book while the setting sun filled the room with soft light. Total peace.
## π Interactive Docs
* Swagger β [http://localhost:8000/docs](http://localhost:8000/docs)
* ReDoc β [http://localhost:8000/redoc](http://localhost:8000/redoc)