Dive deep into your Spotify listening habits and get AI-powered personality insights and song recommendations!
This project leverages the Spotify Web API to extract detailed information about your saved tracks (or any playlist) and uses the OpenAI API (GPT-3.5/GPT-4) to generate a personalized analysis of your music taste and suggest new songs you might love.
- Overview
- Features
- Tech Stack
- Getting Started
- Usage
- Project Visualization
- Contributing
- License
- Acknowledgments
AI Music Analyzer connects to your Spotify account, fetches data about your music preferences (like saved tracks or specific playlists), analyzes various attributes including track details, artist information, and audio features (like danceability, energy, valence), and then passes this data to an AI model (OpenAI's GPT) to:
- Generate a descriptive analysis of the musical profile.
- Infer personality traits based on listening patterns.
- Recommend new songs tailored to the analyzed genres and features.
It's a fun tool for music lovers curious about their habits and data enthusiasts exploring API integrations and AI applications.
- Detailed Spotify Data Extraction: Gathers comprehensive data including track name, artist, album, release date, duration, popularity, explicitness, genres, and audio features.
- AI-Powered Analysis: Utilizes OpenAI's GPT models to interpret music data and generate insightful text.
- Personality Insights: Offers a unique perspective on how music taste might reflect personality traits.
- Personalized Recommendations: Suggests new tracks based on the analysis of existing playlists or saved songs.
- Environment Variable Management: Securely handles API keys using
.envfiles. - Easy to Run: Simple Python script execution.
- Language: Python 3.7+
- APIs:
- Spotify Web API (via
spotipy) - OpenAI API (via
openai)
- Spotify Web API (via
- Data Handling:
pandas - Environment Variables:
python-dotenv
Follow these steps to set up and run the project locally.
- Python 3.7 or later
- Git
- A Spotify account (Premium not required, but needed for some features)
- An OpenAI API key
-
Clone the repository:
git clone https://github.com/PatricRc/ChatGPT-Spotify-Analyzer.git cd ChatGPT-Spotify-Analyzer -
Set up a virtual environment (Recommended):
- On macOS/Linux:
python3 -m venv env source env/bin/activate - On Windows:
python -m venv env .\env\Scripts\activate
- On macOS/Linux:
-
Install dependencies:
pip install -r requirements.txt
(If
requirements.txtdoesn't exist, you might need to create one based on the imports inMain_code.py:pip install spotipy pandas python-dotenv openai)
-
Spotify API Credentials:
- Go to the Spotify Developer Dashboard.
- Create an App. Note the
Client IDandClient Secret. - Edit the settings for your app and add a
Redirect URI. For local development,http://localhost:8888/callbackis common. Make sure this matches theredirect_uriin your code or environment variables.
-
OpenAI API Key:
- Get your API key from the OpenAI Platform.
-
Create
.envfile:- In the root directory of the project, create a file named
.env. - Add your credentials like this:
SPOTIFY_CLIENT_ID='YOUR_SPOTIFY_CLIENT_ID' SPOTIFY_CLIENT_SECRET='YOUR_SPOTIFY_CLIENT_SECRET' SPOTIFY_REDIRECT_URI='YOUR_SPOTIFY_REDIRECT_URI' OPENAI_KEY='YOUR_OPENAI_API_KEY'
- Replace the placeholder values with your actual credentials.
- In the root directory of the project, create a file named
- Ensure your virtual environment is activated.
- Make sure your
.envfile is correctly configured in the project root. - Run the main script:
python Main_code.py
- The script will:
- Authenticate with Spotify (you might need to authorize it in your browser the first time).
- Fetch your saved tracks (up to the limit set in the script, currently 50).
- Process the data and create a DataFrame.
- Send the DataFrame to OpenAI's API using a predefined prompt.
- Print the AI-generated analysis and song recommendations to the console.
- Customization: You can modify the
promptvariable withinMain_code.pyto change the type of analysis or recommendations requested from the AI. You can also adjust thelimitinsp.current_user_saved_tracks(limit=50)to fetch more songs (up to Spotify's API limits). - Jupyter Notebook: For a more interactive exploration, check out the
SpotifyAPI_ChatGPT.ipynbnotebook which includes steps for analyzing different playlists and manual authentication examples.
Here's a glimpse of the data analysis process:
(Consider adding a screenshot of the terminal output showing the AI analysis)
Contributions are welcome! If you have suggestions for improvements or new features, feel free to:
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Please ensure your code adheres to good practices and includes relevant documentation.
Distributed under the MIT License. See LICENSE file for more information.
- Spotify Web API
- OpenAI API
- Spotipy Documentation
- Readme template inspiration (othneildrew/Best-README-Template)
