import pickle


def classify_rows(df):
    """
    Input sonic features of song segments and use pickled classifier model.
    Predict the genre of each row and return the average results for each
    genre. Set location of model depending on if being run from flask app.
    """
    if __name__ == 'archive.genres':
        pkl_fp = 'archive/10genre_clf.pkl'
    else:
        pkl_fp = '10genre_clf.pkl'
    with open(pkl_fp, 'rb') as f:
        model = pickle.load(f)
    
    seg_preds = model.predict_proba(df.drop(['song', 'genre'], axis=1))
    preds = 100 * seg_preds.sum(axis=0)/seg_preds.sum()
    return [(g,p) for g, p in zip(model.classes_, preds.round(3))]