diff --git a/model_service/views/cnn_view.py b/model_service/views/cnn_view.py index 539ce37..341d774 100644 --- a/model_service/views/cnn_view.py +++ b/model_service/views/cnn_view.py @@ -14,6 +14,9 @@ class CNNView(FlaskView): aimodel_schema = AIModelSchema(many=False) info_schema = InfoSchema(many=False) + MODEL_DIRECTORY = "model/" + WEIGHTS_DIRECTORY = "weights/" + @multipart_required def post(self): @@ -46,11 +49,21 @@ class CNNView(FlaskView): m = AIModel(id=info['id'], type=AIModelType.cnn, target_class_name=info['target_class_name']) # Put files into MinIO - storage.connection.put_object(current_app.config['MINIO_CNN_BUCKET_NAME'], "model/" + str(m.id), model_file, - model_file.content_length, content_type=model_file.content_type) + storage.connection.put_object( + current_app.config['MINIO_CNN_BUCKET_NAME'], + self.MODEL_DIRECTORY + str(m.id), + model_file, + model_file.content_length, + content_type=model_file.content_type + ) - storage.connection.put_object(current_app.config['MINIO_CNN_BUCKET_NAME'], "weights/" + str(m.id), weights_file, - weights_file.content_length, content_type=weights_file.content_type) + storage.connection.put_object( + current_app.config['MINIO_CNN_BUCKET_NAME'], + self.WEIGHTS_DIRECTORY + str(m.id), + weights_file, + weights_file.content_length, + content_type=weights_file.content_type + ) db.session.add(m) db.session.commit() @@ -65,8 +78,8 @@ class CNNView(FlaskView): else: m = AIModel.query.filter_by(type=AIModelType.cnn, id=id_).first_or_404() - storage.connection.remove_object(current_app.config['MINIO_CNN_BUCKET_NAME'], "weights/" + str(m.id)) - storage.connection.remove_object(current_app.config['MINIO_CNN_BUCKET_NAME'], "model/" + str(m.id)) + storage.connection.remove_object(current_app.config['MINIO_CNN_BUCKET_NAME'], self.WEIGHTS_DIRECTORY + str(m.id)) + storage.connection.remove_object(current_app.config['MINIO_CNN_BUCKET_NAME'], self.MODEL_DIRECTORY + str(m.id)) db.session.delete(m) db.session.commit() @@ -83,9 +96,9 @@ class CNNView(FlaskView): m = AIModel.query.filter_by(type=AIModelType.cnn, id=id_).first_or_404() if "weights" in request.args: - path = "weights/" + str(m.id) + path = self.WEIGHTS_DIRECTORY + str(m.id) else: - path = "model/" + str(m.id) + path = self.MODEL_DIRECTORY + str(m.id) try: data = storage.connection.get_object(current_app.config['MINIO_CNN_BUCKET_NAME'], path) diff --git a/model_service/views/svm_view.py b/model_service/views/svm_view.py index d97ed86..06eba90 100644 --- a/model_service/views/svm_view.py +++ b/model_service/views/svm_view.py @@ -17,6 +17,9 @@ class SVMView(FlaskView): aimodel_schema = AIModelSchema(many=False) info_schema = InfoSchema(many=False) + MODEL_DIRECTORY = "model/" + MEANS_DIRECTORY = "means/" + @multipart_required def post(self): @@ -65,13 +68,13 @@ class SVMView(FlaskView): # Because of pyAudiomeme the files already saved, so we just use the file uploader functions storage.connection.fput_object( current_app.config['MINIO_SVM_BUCKET_NAME'], - "model/" + str(info['id']), + self.MODEL_DIRECTORY + str(info['id']), temp_model_filename ) storage.connection.fput_object( current_app.config['MINIO_SVM_BUCKET_NAME'], - "means/" + str(info['id']), + self.MEANS_DIRECTORY + str(info['id']), temp_means_filename ) @@ -104,8 +107,8 @@ class SVMView(FlaskView): else: m = AIModel.query.filter_by(type=AIModelType.svm, id=id_).first_or_404() - storage.connection.remove_object(current_app.config['MINIO_SVM_BUCKET_NAME'], "means/" + str(m.id)) - storage.connection.remove_object(current_app.config['MINIO_SVM_BUCKET_NAME'], "model/" + str(m.id)) + storage.connection.remove_object(current_app.config['MINIO_SVM_BUCKET_NAME'], self.MEANS_DIRECTORY + str(m.id)) + storage.connection.remove_object(current_app.config['MINIO_SVM_BUCKET_NAME'], self.MODEL_DIRECTORY + str(m.id)) db.session.delete(m) db.session.commit() @@ -123,9 +126,9 @@ class SVMView(FlaskView): m = AIModel.query.filter_by(type=AIModelType.svm, id=id_).first_or_404() if "means" in request.args: - path = "means/" + str(m.id) + path = self.MEANS_DIRECTORY + str(m.id) else: - path = "model/" + str(m.id) + path = self.MODEL_DIRECTORY + str(m.id) try: data = storage.connection.get_object(current_app.config['MINIO_SVM_BUCKET_NAME'], path)