File size: 1,168 Bytes
6f847ac
31806c5
6f847ac
31806c5
 
 
 
 
 
 
 
 
e92ba0d
6f847ac
 
 
 
 
 
e92ba0d
 
30dd301
e92ba0d
 
 
24f2542
 
6f847ac
 
e92ba0d
 
 
 
31806c5
6f847ac
e92ba0d
 
 
 
 
 
f9846ff
 
c2ccf60
31806c5
3563daa
c2ccf60
 
 
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
from flask import Flask, request, jsonify, make_response

from dataset.random import random_dataset
from opts import options

app = Flask(
    __name__,
    static_folder="static",
    template_folder="templates",
)


def not_valid(params: dict):
    """
    is_valid() simply checks if
    an incoming response is valid
    for this api or not. Key to
    avoiding errors
    """
    if "algorithm" not in params:
        return "User did not specify the algorithm parameter"

    if params["algorithm"] not in options:
        return f"Invalid algorithm '{params['algorithm']}' is invalid."
    return False


@app.route("/", methods=["GET"])
def index():
    params = request.json
    error_message = not_valid(params=params)
    if error_message:
        return make_response(error_message, 400)

    # parse arguments
    algorithm = options[params["algorithm"]]
    args = params["arguments"]

    # in the future instead of a random data set
    # we should do a more real one like palmer penguins
    X, y = random_dataset(100, 10)
    model = algorithm(X, y, args)
    return jsonify(model)


if __name__ == "__main__":
    app.run(
        debug=True,
    )