Jensen-holm commited on
Commit
e92ba0d
·
1 Parent(s): 6f847ac

working on debugging parameters inside of neural network

Browse files
Files changed (1) hide show
  1. app.py +22 -23
app.py CHANGED
@@ -10,44 +10,43 @@ app = Flask(
10
  )
11
 
12
 
13
- def is_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 not request.json():
21
- return False
22
 
23
- if "Algorithm" not in params:
24
- return False
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
- params = request.json()
35
- if not is_valid(params=params):
36
- return make_response(400, "bad request")
37
 
38
  # parse arguments
39
- algorithm = options[params["Algorithm"]]
40
- args = options[params["Arguments"]]
41
-
42
- X, y = random_dataset()
43
- results = algorithm.main(
44
- X=X,
45
- y=y,
46
- args=args,
 
 
 
 
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(