def run(): try: if not flask.request.is_json: response = flask.Response() response.status_code = 400 response.status = 'Error: Not JSON' return response request_data = flask.request.get_json() directory = request_data['url'] settings = Settings() settings.__dict__.update(request_data) # if not settings.exists(): # settings.save() # else: # settings.load() cluster = ClusterRegistry.get(settings.cluster) model = ModelBuilder.create( settings.architecture, settings.dataset, settings.loss, settings.optimizer, settings.metrics, settings.epochs, settings.patience, ) split = model.split(settings.split) results = main(directory, cluster, settings.clusterArgs, split) results = flask.jsonify(results) return results except TrainingIncompleteException: response = flask.Response() response.status_code = 400 response.status = 'Error: Training incomplete' return response except ModelStateMissingError: response = flask.Response() response.status_code = 400 response.status = 'Error: Model state missing' return response except BadModelSettings: response = flask.Response() response.status_code = 400 response.status = 'Error: Incompatible architecture/dataset' return response except ClusterRegistryNameError: response = flask.Response() response.status_code = 400 response.status = 'Error: Bad cluster name' return response except: print_exc() response = flask.Response() response.status_code = 500 response.status = 'Error: Unknown' return response
def cluster(): try: if not flask.request.is_json: response = flask.Response() response.status_code = 400 response.status = 'Error: Not JSON' return response settings = flask.request.get_json() images = ImageDirectory(settings['directory']).jpeg(False) cluster = ClusterRegistry.get(settings['cluster']) results = cluster.run_cached(images, **settings['args']).urls() results = flask.jsonify(results) return results except ClusterRegistryNameError: response = flask.Response() response.status_code = 400 response.status = 'Error: Unknown clustering algorithm' return response except: print_exc() response = flask.Response() response.status_code = 500 response.status = 'Error: Unknown' return response