import json


def label_mapping(category_names = 'cat_to_name.json'):
    
    """
    Function loads in a mapping from category label to category name and creates
    a dictionary from it where the keys are the indices and the values the names.
    
    Parameters:
     category_names - name of the file (has to be in the folger "ImageClassifier"
    Returns:
     cat_to_name - dictionary mapping the integer encoded categories to the actual 
     names of the flowers.
    """
    
    ## Create string
    path_category_names = 'ImageClassifier/' + category_names
    
    ## Load in a mapping from category label to category name (JSON object)
    with open(path_category_names, 'r') as f:
        name_mapping = json.load(f)
        
        # Create a dictionary where the keys are the numbers (converted from string
        # to integers) and the values are the names
        name_mapping = {int(k):v for k,v in name_mapping.items()}
    
    ## Return the dictionary
    return name_mapping