An open API service indexing awesome lists of open source software.

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

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)