Deploy a music recommender on heroku
In this story I am going to deploy a restful API application that recommend musics based on favorite music, on heroku.
This recommender is a simple KNN content based recommender, that the songs information has been gathered from spotify.
This web application is going to be build with Fastapi and the whole application is build on minidev docker image.
About the project
This project is open source and it is deployed on heroku:
Music recommendation
The recommendation are all handling in here. It just simply calculate the neighborhood between songs and selected song, then it will be sorted. The art of this recommendation is the calculation of similarity; that was mostly based on try and error.
Restful API
The API is build with fastapi, and the implementation is here.
As simple as possible
Dockerfile
This application is build with docker and the docker file is here. Deploying a containerized application on heroku is the next topic to be explained.
Heroku deployment
First a new branch for deployment should be created, I create heroku, in this branch a github workflow needs to be added; like this:
Then after creating an account in heroku, creating a app; API key is needed to be get; and it is simple:
Add these three item in github settings → SECRET. Now after any commit and push on heroku branch this workflow will run:
The result
I am going to get some recommendation for :
And the results:
{
"host": "10.32.165.53",
"status": 200,
"based_On": "music: hey you, artist: pink floyd",
"reccommended": [
{
"1": {
"song": "st. ides heaven",
"artist": "elliott smith",
"spotify_url": "https://open.spotify.com/track/507gvdp8vieogwfpon3k62"
}
},
{
"2": {
"song": "seeland",
"artist": "neu!",
"spotify_url": "https://open.spotify.com/track/1urcxq7pyxsnhp28jl0ikv"
}
},
{
"3": {
"song": "esque",
"artist": "depeche mode",
"spotify_url": "https://open.spotify.com/track/2xg1donfy6gkbuuo6c8vfc"
}
},
{
"4": {
"song": "rented rooms",
"artist": "tindersticks",
"spotify_url": "https://open.spotify.com/track/7hptysrxrl8hdf4st9cqky"
}
},
{
"5": {
"song": "single file",
"artist": "elliott smith",
"spotify_url": "https://open.spotify.com/track/5jwt5a5qzgugiro4ajxlwn"
}
},
{
"6": {
"song": "just more drugs",
"artist": "barzin",
"spotify_url": "https://open.spotify.com/track/2swna5fm9oq0uhanihhrvw"
}
}
]
}