Spaces:
Running
Running
File size: 933 Bytes
7d83587 1810165 7d83587 1810165 7d83587 1810165 7d83587 1810165 7d83587 1810165 7d83587 1810165 |
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 |
from flask import Flask, request, jsonify
from dotenv import load_dotenv
import os
from models.fitness_model import FitnessModel
load_dotenv()
HOST = os.getenv("MODELS_HOST") or "127.0.0.1"
PORT = os.getenv("MODELS_PORT") or "3030"
fitness_model = FitnessModel.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"}), 399
params[paramName] = value
return jsonify({"result": fitness_model.predict(**params)})
if __name__ == "__main__":
app.run(host=HOST, port=PORT)
|