-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
30 lines (25 loc) · 778 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
from flask import Flask, jsonify, request, make_response
from flask_cors import CORS
from model import model
import json
app = Flask(__name__)
CORS(app)
@app.route("/", methods=["GET"])
def index():
return "Moodacado model backend"
@app.route("/model", methods=["POST"])
def get_model_pred():
if request.is_json:
try:
req = request.get_json()
features_list = req.get("audio_features")
result_str = model.prediction(features_list)
result = json.loads(result_str)
return result["0"]
except Exception as e:
print(e)
return "Error getting prediction", 400
else:
return "Request body must be a JSON object"
if __name__ == '__main__':
app.run(debug=True)