import os import pandas as pd import datasets # Define the dataset class MyCsvDataset(datasets.GeneratorBasedBuilder): def _info(self): return datasets.DatasetInfo( features=datasets.Features({ "TrackName": datasets.Value("string"), "TrackID": datasets.Value("int32"), "SampleURL": datasets.Value("string"), "ReleaseYear": datasets.Value("int32"), "Genres": datasets.Value("string"), "danceability": datasets.Value("float32"), "energy": datasets.Value("float32"), "loudness": datasets.Value("float32"), "speechiness": datasets.Value("float32"), "acousticness": datasets.Value("float32"), "instrumentalness": datasets.Value("float32"), "liveness": datasets.Value("float32"), "valence": datasets.Value("float32"), "tempo": datasets.Value("float32"), "key": datasets.Value("int32"), "mode": datasets.Value("int32"), "duration_ms": datasets.Value("int32"), "Popularity": datasets.Value("int32"), "pNum": datasets.Value("int32"), "playlistID": datasets.Value("string"), "label": datasets.Value("string"), "userCat": datasets.Value("string"), "demoCat": datasets.Value("string"), "length": datasets.Value("int32"), "playlistTitle": datasets.Value("string"), "nFoll": datasets.Value("int32"), "nTracks": datasets.Value("int32"), }) ) def _split_generators(self, dl_manager): # Define the dataset splits data_dir = dl_manager.download_and_extract("path_to_your_data") csv_file = os.path.join(data_dir, "your_dataset.csv") return [ datasets.SplitGenerator( name=datasets.Split.TRAIN, gen_kwargs={"csv_file": csv_file}, ), ] def _generate_examples(self, csv_file): # Yield examples from the CSV file df = pd.read_csv(csv_file) for idx, row in df.iterrows(): yield idx, { "TrackName": row["TrackName"], "TrackID": row["TrackID"], "SampleURL": row["SampleURL"], "ReleaseYear": row["ReleaseYear"], "Genres": row["Genres"], "danceability": row["danceability"], "energy": row["energy"], "loudness": row["loudness"], "speechiness": row["speechiness"], "acousticness": row["acousticness"], "instrumentalness": row["instrumentalness"], "liveness": row["liveness"], "valence": row["valence"], "tempo": row["tempo"], "key": row["key"], "mode": row["mode"], "duration_ms": row["duration_ms"], "Popularity": row["Popularity"], "pNum": row["pNum"], "playlistID": row["playlistID"], "label": row["label"], "userCat": row["userCat"], "demoCat": row["demoCat"], "length": row["length"], "playlistTitle": row["playlistTitle"], "nFoll": row["nFoll"], "nTracks": row["nTracks"], }