-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
35 lines (24 loc) · 953 Bytes
/
app.py
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
from flask import Flask, jsonify, request
from app.services import recommender_service
import ConfigParser
from flask_pymongo import PyMongo
app = Flask(__name__)
config = ConfigParser.ConfigParser()
config.read('app/configs/local.env')
app.config['MONGO_DBNAME'] = config.get('MONGO', 'db.db')
app.config['MONGO_URI'] = config.get('MONGO', 'db.uri')
mongo = PyMongo(app)
@app.route('/api/recommender/v1/model/create', methods=['GET'])
def create_model():
_id = request.args.get('id')
recommender_service.create_model(mongo, _id)
return jsonify({"status": 200})
@app.route('/api/recommender/v1/recommend', methods=['GET'])
def recommend():
_id = request.args.get('id')
user = request.args.get('user')
k = request.args.get('k')
objects = recommender_service.recommend(mongo, _id, user, k)
return jsonify({"status": 200, "data": {"recommendations": objects}})
if __name__ == '__main__':
app.run(debug=True)