Spaces:
Sleeping
Sleeping
File size: 1,042 Bytes
6f847ac 31806c5 6f847ac 31806c5 6f847ac 30dd301 6f847ac c2ccf60 31806c5 6f847ac 24f2542 6f847ac 31806c5 6f847ac c2ccf60 6f847ac 31806c5 30dd301 c2ccf60 |
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 |
from flask import Flask, request, jsonify, make_response
from dataset.random import random_dataset
from opts import options
app = Flask(
__name__,
static_folder="static",
template_folder="templates",
)
def is_valid(params: dict):
"""
is_valid() simply checks if
an incoming response is valid
for this api or not. Key to
avoiding errors
"""
if not request.json():
return False
if "Algorithm" not in params:
return False
if params["Algorithm"] not in options:
return False
return True
@app.route("/", methods=["GET"])
def index():
params = request.json()
if not is_valid(params=params):
return make_response(400, "bad request")
# parse arguments
algorithm = options[params["Algorithm"]]
args = options[params["Arguments"]]
X, y = random_dataset()
results = algorithm.main(
X=X,
y=y,
args=args,
)
return jsonify(results)
if __name__ == '__main__':
app.run(
debug=True,
)
|