Spaces:
Sleeping
Sleeping
Jensen-holm
commited on
Commit
•
192a1c0
1
Parent(s):
3563daa
allowing a get request just cause
Browse files- app.py +18 -17
- templates/index.html +12 -0
app.py
CHANGED
@@ -1,11 +1,10 @@
|
|
1 |
-
from flask import Flask, request, jsonify, make_response
|
2 |
|
3 |
from dataset.random import random_dataset
|
4 |
from opts import options
|
5 |
|
6 |
app = Flask(
|
7 |
__name__,
|
8 |
-
static_folder="static",
|
9 |
template_folder="templates",
|
10 |
)
|
11 |
|
@@ -25,22 +24,24 @@ def not_valid(params: dict):
|
|
25 |
return False
|
26 |
|
27 |
|
28 |
-
@app.route("/", methods=["GET"])
|
29 |
def index():
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
|
|
|
|
44 |
|
45 |
|
46 |
if __name__ == "__main__":
|
|
|
1 |
+
from flask import Flask, request, jsonify, make_response, render_template
|
2 |
|
3 |
from dataset.random import random_dataset
|
4 |
from opts import options
|
5 |
|
6 |
app = Flask(
|
7 |
__name__,
|
|
|
8 |
template_folder="templates",
|
9 |
)
|
10 |
|
|
|
24 |
return False
|
25 |
|
26 |
|
27 |
+
@app.route("/", methods=["POST", "GET"])
|
28 |
def index():
|
29 |
+
if request.method == "POST":
|
30 |
+
params = request.json
|
31 |
+
error_message = not_valid(params=params)
|
32 |
+
if error_message:
|
33 |
+
return make_response(error_message, 400)
|
34 |
+
|
35 |
+
# parse arguments
|
36 |
+
algorithm = options[params["algorithm"]]
|
37 |
+
args = params["arguments"]
|
38 |
+
|
39 |
+
# in the future instead of a random data set
|
40 |
+
# we should do a more real one like palmer penguins
|
41 |
+
X, y = random_dataset(100, 10)
|
42 |
+
model = algorithm(X, y, args)
|
43 |
+
return jsonify(model)
|
44 |
+
return render_template("index.html")
|
45 |
|
46 |
|
47 |
if __name__ == "__main__":
|
templates/index.html
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html>
|
3 |
+
<head>
|
4 |
+
<title>Data Mining From Scratch Backend</title>
|
5 |
+
</head>
|
6 |
+
<body>
|
7 |
+
<h1>Data Mining From Scratch Backend</h1>
|
8 |
+
<p>This is the backend source code for Data Mining From Scratch.</p>
|
9 |
+
<p>You can find the code on <a href="https://github.com/Jensen-holm/Data-Mining-From-Scratch-Backend">GitHub</a>.</p>
|
10 |
+
</body>
|
11 |
+
</html>
|
12 |
+
|