File size: 1,411 Bytes
714bc51
2c9d2bf
31806c5
6377159
31806c5
 
f38f95f
 
f31d9cf
 
 
31806c5
 
 
 
 
28d5b3d
24f2542
f38f95f
 
24f2542
f31d9cf
6f847ac
f31d9cf
f04bbb4
 
f38f95f
 
 
 
 
 
d13c92f
 
 
f38f95f
 
 
 
33e7a34
f31d9cf
 
6377159
deecb43
f31d9cf
 
 
 
 
 
 
 
 
 
 
 
f04bbb4
3cab2dd
 
 
f31d9cf
3cab2dd
6377159
3cab2dd
c2ccf60
31806c5
3563daa
a18c74f
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
59
60
61
62
63
64
65
66
67
68
69
from flask import Flask, request, jsonify, render_template
from flask_cors import CORS

from dataset.iris import iris
from opts import options

import os

# using the iris data set for every algorithm
X, y = iris()

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

CORS(app, origins="*")

UPLOAD_FOLDER = os.getcwd() + "/plots"


@app.route("/", methods=["GET"])
def index():
    return render_template("index.html")


@app.route("/plots/<plt_key>", methods=["GET"])
def get_plot(plt_key):
    filename = f"{plt_key}.png"
    filepath = os.path.join(UPLOAD_FOLDER, filename)

    if os.path.isfile(filepath):
        with open(filepath, "rb") as file:
            plot_bytes = file.read()
        return plot_bytes, 200, {"Content-Type": "image/png"}
    else:
        return "Plot not found", 404


@app.route("/neural-network", methods=["POST"])
def neural_network():
    algorithm = options["neural-network"]
    args = request.json["arguments"]

    result = algorithm(
        X=X,
        y=y,
        args=args,
    )
    return jsonify(result)


@app.route("/kmeans-clustering", methods=["POST"])
def kmeans():
    algorithm = options["kmeans-clustering"]
    args = request.json["arguments"]

    result = algorithm(
        X=X,
        y=y,
        clusterer="kmeans-clustering",
        args=args,
    )
    return jsonify(result)


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