Last active
December 25, 2018 18:21
-
-
Save jainanchit51/fa372b4c7d5bbeb372ff01281d8d6e1c to your computer and use it in GitHub Desktop.
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
# function that returns the 30 most similar movies based on the cosine similarity score. | |
from flask import Flask | |
app = Flask(__name__) | |
@app.route("/") | |
def main(): | |
title = request.args.get('movie') | |
idx = indices[title] | |
print("Index",idx) | |
similar_scores = list(enumerate(cosine_sim[idx])) | |
similar_scores = sorted(similar_scores, key=lambda x: x[1], reverse=True) | |
similar_scores = similar_scores[1:6] | |
movie_indices = [i[0] for i in similar_scores] | |
output = [] | |
for item in titles.iloc[movie_indices]: | |
output.append(item) | |
return json.dumps(output) | |
if __name__ == "__main__": | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment