File size: 1,297 Bytes
2a021c2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from flask import Flask, request, jsonify
from dotenv import load_dotenv
from models.fitness_model import FitnessModel
from models.nutrition_model import NutritionModel

load_dotenv()


fitness_model = FitnessModel.load()
nutrition_model = NutritionModel()
nutrition_model.load()
app = Flask("model-server")


@app.get("/")
def health():
    return "I'm alive!!"


@app.post("/fitness")
def fitness_predict():
    paramNames = [
        "home_or_gym",
        "level",
        "goal",
        "gender",
        "age",
        "feedback",
        "old_weight",
        "equipments",
    ]

    params = {}
    for paramName in paramNames:
        value = request.json.get(paramName)
        if value is None:
            return jsonify({"error": f"{paramName} is missing"}), 400
        params[paramName] = value

    return jsonify({"result": fitness_model.predict(**params)})


@app.post("/nutrition")
def nutrition_predict():
    paramNames = ["calories"]

    params = {}
    for paramName in paramNames:
        value = request.json.get(paramName)
        if value is None:
            return jsonify({"error": f"{paramName} is missing"}), 400
        params[paramName] = value
    return jsonify({"result": nutrition_model.generate_plan(**params)})


if __name__ == "__main__":
    app.run()