DEV Community

Cover image for Synsong: A prompt-based playlist generator
Victoria Slocum
Victoria Slocum

Posted on

Synsong: A prompt-based playlist generator

Super excited to announce the beginnings of Synsong!


TLDR:

I just somewhat finished the beta of a project (synsong.app) to practice NLP, Python, and API skills. Right now, you can input genre, popularity, and a natural language prompt (such as a sentence, quote, or paragraph), and it will create a playlist based on matches with the lyrics, song title, and artist name with the prompt. Eventual goals are to practice model training to auto-detect genres, do some topic modeling with larger prompts, and maybe even have an option for mood.


The Beginnings

The beginnings of synsong have been super fun. It started with the idea, to make a playlist from a sentence, and ended with a whole bunch of other playlist customizations, such as genre and popularity. I made the backend first, and then also created the website.

The Backend

The backend is written in Python, and uses spaCy for all the NLP. I started out by getting the title, spaCy gets of the noun phrases through looking at dependencies (nsubj or pobj) or heads (lemma_ == "be"). The constituents that are searched in the lyrics are found using spaCy's .noun_chunks function. For both the title and the constituents, a random sample is taken (1 for the title and 5 for the constituents).

The constituents are then put in a series of lists with differing amounts of items to ensure that relavant but enough results come up.

# prompt: Potatoes are great food for worms and bugs in the ground.

[['potato', 'great food', 'worm', 'bug', 'ground'], ['great food', 'bug', 'ground'], ['worm', 'bug', 'ground'], ['potato', 'great food', 'worm', 'bug'], ['potato', 'worm', 'bug', 'ground'], ['great food', 'worm', 'bug', 'ground'], ['potato'], ['great food'], ['worm'], ['bug'], ['ground']]
Enter fullscreen mode Exit fullscreen mode

The lists are then formatted and searched through the Musixmatch database with the inputted genre and popularity filters. If there's more than 30 songs, the code will just take the first 30, which are probably the most relevant ones due to the ordering of the search.

I then used Spotipy to link the user's Spotify account and make a playlist on their behalf.

That's basically it! You can find all the code in the GitHub.

The Frontend

The website is powered by Flask, a Python web framework, and Bulma, a CSS framework, and then deployed with Railway.

Demo

Synsong starts on the home page, where it will prompt you to “get started” to log in with your Spotify or “go to app” if you’ve already logged in.

Synsong Home

You’ll then go to the generator page...

Synsong Generator

And then you can input your prompt, genres, and other settings!

Synsong Generator Filled

You’ll get a playlist (it takes awhile to load though) on the page after, and you can also see it in your Spotify account.

Synsong Your Playlist

And that’s that!!

Future plans and known issues

I would love to have a whole other aspect of machine learning so I can work on those skills, and one way I’ve thought about doing that is through genre detection. I’d also love to try my hand at topic modeling for larger prompts.

Right now, the popularity filter isn’t too tuned and I’m at a bit of a risk for making too many API requests with Musixmatch’s free plan. Also the footer isn’t stuck to the bottom. Besides that, let me know if you find any other issues!

Links

Thanks for reading! I’m Victoria (victoriaslocum.com), and you can find this projects website at synsong.app and the GitHub here.

Discussion (0)