song-recommender / recommender.py
jrno's picture
add csv data and endpoints to show user track history from it
af5cf7c
raw
history blame
751 Bytes
from fastai.learner import Learner
import pandas as pd
def get_recommendations_for_user(learn: Learner, user_id: str, limit: int = 5):
# TODO: Fetch list of not listened songs as entries
not_listened_songs = ["Revelry, Kings of Leon, 2008", "Gears, Miss May I, 2010", "Sexy Bitch, David Guetta, 2009"]
input_dataframe = pd.DataFrame({'user_id': ["440abe26940ae9d9268157222a4a3d5735d44ed8"] * len(not_listened_songs), 'entry': not_listened_songs})
test_dl = learn.dls.test_dl(input_dataframe)
predictions = learn.get_preds(dl=test_dl)
# TODO: Return recommendations in track format
return {
"user_id": user_id,
"limit": limit,
"recommendations": predictions[0].numpy().tolist()
}