def file_size(file, unit):
    """
    Convert the size from bytes to other units like KB, MB or GB

    Adapted from:
    https://thispointer.com/python-get-file-size-in-kb-mb-or-gb-human-readable-format/
    """

    base = 1024

    if unit == 'KB':
        size = file.size/base
    elif unit == 'MB':
        size = file.size/(base**2)
    elif unit == 'GB':
        size = file.size/(base**3)
    else:
        size = file.size

    return f'{round(size, 2)} {unit}'