MoodMelody is a Flask-based web application that uses OpenAI's GPT-4o-mini model to provide personalized music recommendations. The application also integrates with the Spotify API to create playlists based on the recommendations.
MoodMelody allows users to receive song recommendations based on their mood or specific criteria. Users can then create a Spotify playlist with the recommended songs and listen to it immediately.
- AI-powered song recommendations using OpenAI's GPT-4o-mini model.
- Integration with Spotify API to create and manage playlists.
- Session management for tracking user interactions.
- Python 3.12 or higher
- PostgreSQL
- Git
- Fork the repository on GitHub.
- Clone the repository to your local machine.
git clone https://github.com/your-username/mood_melody_backend.git
cd mood_melody_backend
- Create a virtual environment:
python3 -m venv venv
- Activate the virtual environment:
- On macOS and Linux:
source venv/bin/activate
- On Windows:
venv\Scripts\activate
- Install the required packages:
pip install -r requirements.txt
-
Install PostgreSQL (if not already installed).
-
Create the development and test databases:
psql -U postgres - #To open the Postgres interactive terminal with a Postgres user named postgres
CREATE DATABASE mood_m;
CREATE DATABASE mood_m_test;
\q
- Create a
.env
file in the root directory with the following content:
SQLALCHEMY_DATABASE_URI=postgresql://postgres:password@localhost/mood_m
SQLALCHEMY_TEST_DATABASE_URI=postgresql://postgres:password@localhost/mood_m_test
OPENAI_API_KEY=your_openai_api_key
SPOTIFY_CLIENT_ID=your_spotify_client_id
SPOTIFY_CLIENT_SECRET=your_spotify_client_secret
SPOTIFY_REDIRECT_URI=your_spotify_redirect_uri
- Initialize and apply migrations:
flask db init
flask db migrate -m "Initial migration"
flask db upgrade
- Run the Flask application:
flask run
The application should now be running at http://127.0.0.1:5000/
or http://localhost:5000/
-
Open Postman.
-
Create a new POST request:
- URL:
http://127.0.0.1:5000/recommend
orhttp://localhost:5000/recommend
- Headers: Add a
Session-Id
header with a unique value (optional). - Body: Set to JSON and include a
description
field, for example:
{
"description": "upbeat pop song with a happy vibe"
}
- Send the request and you should receive a JSON response with a song recommendation.
This project is licensed under the MIT License.