def generate_counterfactual(ready_object, query_instance, number_CF, desired_pred, 
                             feature_weights, proximity_weight, diversity_weight, feature_to_vary):

    """
    Generate counterfactual profiles with feature-perturbed versions.
    
    Parameters:
    ready_object: the DiCE class
    query_instance: a query input whose outcome needs to be explained. 
                    query instance shoulde be in the form of a dictionary; keys: feature name, values: feature value
    number_CF: total number of counterfactuals to generate
    desired_pred: the desired outcome of prediction
    feature_weights: a dictionary; keys: continuous feature name, values: weights. 
    proximity_weight: weight for the counterfactuals be closer and feasible to an individual's profile(query instance)
    diversity_weight: weight for the counterfactuals be providing the individual multiple options
    feature_to_vary: a list of features that are allowed to vary since other suggested features are not easily be varied

    Returns:
    
    viz(dataframe): profiles with feature-perturbed versions that will produce a desired prediction
    
    """
    exp = ready_object
    dice_exp = exp.generate_counterfactuals(query_instance = query_instance, total_CFs=number_CF,
                                            desired_class=desired_pred, diversity_weight = diversity_weight)
                                           
    # Visualize counterfactual explanation
    viz = dice_exp.visualize_as_dataframe()
    
    return viz