import os import pandas as pd from datasets import DatasetDict, Dataset, Audio from sklearn.model_selection import train_test_split def load_data(data_dir, test_size=0.2, seed=42): metadata = pd.read_csv(os.path.join(data_dir, "metadata.csv")) # Split the data into train and test subsets train_data, test_data = train_test_split(metadata, test_size=0.2, random_state=seed) # Convert to Hugging Face datasets train_dataset = Dataset.from_pandas(train_data) test_dataset = Dataset.from_pandas(test_data) # Cast the 'path' column to Audio type train_dataset = train_dataset.cast_column("path", Audio()) test_dataset = test_dataset.cast_column("path", Audio()) # Combine into a DatasetDict data = DatasetDict({ "train": train_dataset, "test": test_dataset }) return data # Load and split the dataset data = load_data("my_dataset") print(data)