-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
38 lines (30 loc) 路 864 Bytes
/
Copy pathapp.py
File metadata and controls
38 lines (30 loc) 路 864 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from flask import Flask, request, jsonify, render_template
from flask_cors import CORS
from recommender import recommend, movies
app = Flask(__name__)
CORS(app)
@app.route('/')
def home():
return render_template('index.html')
# 馃攳 autocomplete
@app.route('/search')
def search():
query = request.args.get('q', '').lower()
results = movies[
movies['title'].str.lower().str.contains(query)
]['title'].head(10).tolist()
return jsonify(results)
# 馃幀 recommendations
@app.route('/recommend', methods=['POST'])
def recommend_movies():
movie = request.json['movie']
try:
names, posters = recommend(movie)
return jsonify({
"names": names,
"posters": posters
})
except:
return jsonify({"error": "Movie not found"})
if __name__ == '__main__':
app.run(debug=True)