def export(prediction_id: int): prediction = Prediction.get(prediction_id) if (prediction): stream = prediction.export() return stream else: raise NotFound('Prediction does not exist')
def delete_ml_model(model_id: int): """ Deletes ML model and associated predictions :params model_id """ ml_model = Project.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 delete(uid: int, token_id: int): """ Delete an token :params token """ token = Token.get(uid, token_id) if token: token.delete() return {"status": "deleted"} else: raise NotFound("Token Not Found")
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(uid: int, token_id: int): """ Fetch information about a given token :params token :raises NotFound :returns imagery """ token = Token.get(uid, token_id).as_dto().to_primitive() if token: return token.to_primitive() else: raise NotFound("Token Not Found")
def get_all(uid: int, model_filter: str, model_archived: bool): """ Get all ML Models :raises NotFound :returns array of ML Models """ ml_models = Project.get_all(uid, 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")
def patch(prediction_id: int, update: dict) -> int: """ Patch a prediction by ID :params prediction_id :params update :returns prediction """ prediction = Prediction.get(prediction_id) if (prediction): prediction.link(update) return prediction_id else: raise NotFound('Prediction does not exist')
def get_all(): """ Get all ML Models :raises NotFound :returns array of ML Models """ ml_models = MLModel.get_all() 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')
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 = Project.get(model_id) users = ProjectAccess.list(model_id) if ml_model: model = ml_model.as_dto(users=users) return model else: raise NotFound("Model does not exist")
def update_ml_model(dto: ProjectDTO) -> int: """ Update an existing ML Model :params model_id :raises NotFound :returns model_id """ ml_model = Project.get(dto.model_id) if ml_model: ml_model.update(dto) if dto.users: users = ProjectAccess.list(dto.model_id) ProjectAccess.list_update(dto.model_id, users, dto.users) return dto.model_id else: raise NotFound("Model does not exist")