Spaces:
Sleeping
Sleeping
Commit
·
e92ba0d
1
Parent(s):
6f847ac
working on debugging parameters inside of neural network
Browse files
app.py
CHANGED
@@ -10,44 +10,43 @@ app = Flask(
|
|
10 |
)
|
11 |
|
12 |
|
13 |
-
def
|
14 |
"""
|
15 |
is_valid() simply checks if
|
16 |
an incoming response is valid
|
17 |
for this api or not. Key to
|
18 |
avoiding errors
|
19 |
"""
|
20 |
-
if not
|
21 |
-
return
|
22 |
|
23 |
-
if "
|
24 |
-
return
|
25 |
-
|
26 |
-
if params["Algorithm"] not in options:
|
27 |
-
return False
|
28 |
-
return True
|
29 |
|
30 |
|
31 |
@app.route("/", methods=["GET"])
|
32 |
def index():
|
33 |
-
|
34 |
-
|
35 |
-
if
|
36 |
-
return make_response(
|
37 |
|
38 |
# parse arguments
|
39 |
-
algorithm = options[params["
|
40 |
-
args =
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
|
|
|
|
|
|
|
|
47 |
)
|
48 |
|
49 |
-
return jsonify(results)
|
50 |
-
|
51 |
|
52 |
if __name__ == '__main__':
|
53 |
app.run(
|
|
|
10 |
)
|
11 |
|
12 |
|
13 |
+
def not_valid(params: dict):
|
14 |
"""
|
15 |
is_valid() simply checks if
|
16 |
an incoming response is valid
|
17 |
for this api or not. Key to
|
18 |
avoiding errors
|
19 |
"""
|
20 |
+
if "algorithm" not in params:
|
21 |
+
return "User did not specify the algorithm parameter"
|
22 |
|
23 |
+
if params["algorithm"] not in options:
|
24 |
+
return f"Invalid algorithm '{params['algorithm']}' is invalid."
|
25 |
+
return False
|
|
|
|
|
|
|
26 |
|
27 |
|
28 |
@app.route("/", methods=["GET"])
|
29 |
def index():
|
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 |
+
return jsonify(
|
43 |
+
algorithm(
|
44 |
+
X=X,
|
45 |
+
y=y,
|
46 |
+
args=args,
|
47 |
+
)
|
48 |
)
|
49 |
|
|
|
|
|
50 |
|
51 |
if __name__ == '__main__':
|
52 |
app.run(
|