Spaces:
Sleeping
Sleeping
Commit
·
f38f95f
1
Parent(s):
d57e8af
creating the plot endpoint for getting result images
Browse files
app.py
CHANGED
@@ -1,9 +1,11 @@
|
|
1 |
-
from flask import Flask, request, jsonify, render_template
|
2 |
from flask_cors import CORS
|
3 |
|
4 |
from dataset.iris import iris
|
5 |
from opts import options
|
6 |
|
|
|
|
|
7 |
# using the iris data set for every algorithm
|
8 |
X, y = iris()
|
9 |
|
@@ -14,12 +16,25 @@ app = Flask(
|
|
14 |
|
15 |
CORS(app, origins="*")
|
16 |
|
|
|
|
|
17 |
|
18 |
@app.route("/", methods=["GET"])
|
19 |
def index():
|
20 |
return render_template("index.html")
|
21 |
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
@app.route("/neural-network", methods=["POST"])
|
24 |
def neural_network():
|
25 |
algorithm = options["neural-network"]
|
|
|
1 |
+
from flask import Flask, request, jsonify, render_template, send_file
|
2 |
from flask_cors import CORS
|
3 |
|
4 |
from dataset.iris import iris
|
5 |
from opts import options
|
6 |
|
7 |
+
import os
|
8 |
+
|
9 |
# using the iris data set for every algorithm
|
10 |
X, y = iris()
|
11 |
|
|
|
16 |
|
17 |
CORS(app, origins="*")
|
18 |
|
19 |
+
UPLOAD_FOLDER = os.getcwd() + "/plots"
|
20 |
+
|
21 |
|
22 |
@app.route("/", methods=["GET"])
|
23 |
def index():
|
24 |
return render_template("index.html")
|
25 |
|
26 |
|
27 |
+
@app.route("/plots/<plt_key>", methods=["GET"])
|
28 |
+
def get_plot(plt_key):
|
29 |
+
filename = f"{plt_key}.png"
|
30 |
+
filepath = os.path.join(UPLOAD_FOLDER, filename)
|
31 |
+
|
32 |
+
if os.path.isfile(filepath):
|
33 |
+
return send_file(filepath, mimetype='image/png')
|
34 |
+
else:
|
35 |
+
return "Plot not found", 404
|
36 |
+
|
37 |
+
|
38 |
@app.route("/neural-network", methods=["POST"])
|
39 |
def neural_network():
|
40 |
algorithm = options["neural-network"]
|