Created
December 7, 2020 05:31
-
-
Save steven-tey/88d040fe3c4942f9566ed6d4f79ca4c0 to your computer and use it in GitHub Desktop.
Main recommender driver function for model.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def make_recommendation(query, metadata=metadata): | |
new_row = metadata.iloc[-1,:].copy() | |
new_row.iloc[-1] = query | |
metadata = metadata.append(new_row) | |
count = CountVectorizer(stop_words='english') | |
count_matrix = count.fit_transform(metadata['soup']) | |
cosine_sim2 = cosine_similarity(count_matrix, count_matrix) | |
sim_scores = list(enumerate(cosine_sim2[-1,:])) | |
sim_scores = sorted(sim_scores, key=lambda x: x[1], reverse=True) | |
ranked_titles = [] | |
for i in range(1, 11): | |
indx = sim_scores[i][0] ranked_titles.append([metadata['title'].iloc[indx], metadata['imdb_id'].iloc[indx], metadata['runtime'].iloc[indx], metadata['release_date'].iloc[indx], metadata['vote_average'].iloc[indx]]) | |
return ranked_titles | |
@app.route("/get") | |
@cross_origin() | |
def get_recommendations(): | |
userText = request.args.get('msg') | |
response = make_recommendation(str(userText)) | |
return jsonify(response) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment