예제 #1
0
def predict_image():
    if request.method == 'POST':
        # Step 1: check if the post request has the file part
        if 'file' not in request.files:
            return jsonify('No file found'), 400

        file = request.files('file')

        # Step 2: Basic file extension validation
        if file and allowed_file(file.filename):

            # Step 3: Save the file
            # Note, in production, this would require careful
            # validation, management and clean up

            file.save(os.path.join(UPLOAD_FOLDER, filename))

            _logger.debug(f'Inputs: {filename}')

            # Step 4: perform predictions
            result = make_single_prediction(
                image_name=filename,
                image_directory=UPLOAD_FOLDER)

            _logger.debug(f'Outputs: {result}')

        readable_predictions = result.get('readable_predictions')
        version = result.get('version')

        # Step 5: Return the response as JSON
        return jsonify({'readable_predictions': readable_predictions[0],
                        'version': version})
def predict_video():
    if request.method == 'POST':
        #check if the post request has the file part
        if 'file' not in request.files:
            return jsonify('no file found') , 400
        file=request.files['file']

        #Basic file extension validation

        if file and allowed_file(file.filename):
            filename=secure_filename(file.filename)

        # save the file to upload directory
        file.save(os.path.join(UPLOAD_FOLDER,filename))

        _logger.debug(f'inputs: {filename}')

        #perform predction

        result =make_single_prediction(video_name=filename,
                                        video_directory=UPLOAD_FOLDER)
        _logger.debug(f'Outputs: {result}')

        readable_predictions = result.get('readable_predictions')
        version = result.get('version')
        # return the output results
        return jsonify(
            {'readable_predictions': readable_predictions[0],
             'version': version})