def subscribe_ml_model(ml_model_dto: MLModelDTO) -> int: """ Subscribes an ML Model by saving it in the database :params ml_model_dto :raises DataError :returns ID of the ml model """ new_ml_model = MLModel() new_ml_model.create(ml_model_dto) current_app.logger.info(new_ml_model) return new_ml_model.id
def delete_ml_model(model_id: int): """ Deletes ML model and associated predictions :params model_id """ ml_model = MLModel.get(model_id) if ml_model: ml_model.delete() else: raise NotFound('Model does not exist')
def get_ml_model_by_id(model_id: int): """ Get an ML Model for a given ID :params model_id :raises NotFound :returns ML Model """ ml_model = MLModel.get(model_id) if ml_model: return ml_model.as_dto() else: raise NotFound('Model does not exist')
def tilejson(model_id, prediction_id): """ Get the TileJSON of the prediction id given :params model_id :params prediction_id :returns dict """ tiles = PredictionTile.count(prediction_id) if tiles.count == 0: raise PredictionsNotFound('No Prediction Tiles exist') ml_model = MLModel.get(model_id) prediction = Prediction.get(prediction_id) tilejson = { "tilejson": "2.1.0", "name": ml_model.name, "description": ml_model.project_url, "inferences": PredictionTile.inferences(prediction_id), "token": CONFIG.EnvironmentConfig.MAPBOX_TOKEN, "attribution": ml_model.source, "version": prediction.version, "scheme": "xyz", "type": "vector", "tiles": [ "/v1/model/{0}/prediction/{1}/tiles/{{z}}/{{x}}/{{y}}.mvt". format(model_id, prediction_id) ], "minzoom": 0, "maxzoom": prediction.tile_zoom, "bounds": PredictionTile.bbox(prediction_id) } return tilejson
def update_ml_model(updated_ml_model_dto: MLModelDTO) -> int: """ Update an existing ML Model :params model_id :raises NotFound :returns model_id """ ml_model = MLModel.get(updated_ml_model_dto.model_id) if (ml_model): ml_model.update(updated_ml_model_dto) return updated_ml_model_dto.model_id else: raise NotFound('Model does not exist')
def get_all(model_filter: str, model_archived: bool): """ Get all ML Models :raises NotFound :returns array of ML Models """ ml_models = MLModel.get_all(model_filter, model_archived) if (ml_models): model_collection = [] for model in ml_models: model_collection.append(model.as_dto().to_primitive()) return model_collection else: raise NotFound('No models exist')