Datasets:
Delete convert_to_parquet.py
Browse files- convert_to_parquet.py +0 -64
convert_to_parquet.py
DELETED
|
@@ -1,64 +0,0 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import csv
|
| 3 |
-
from datasets import Dataset, Audio, Features, Value, Version
|
| 4 |
-
|
| 5 |
-
# Point to the current directory
|
| 6 |
-
dataset_path = os.path.dirname(os.path.abspath(__file__))
|
| 7 |
-
|
| 8 |
-
# Dataset metadata
|
| 9 |
-
VERSION = Version("1.0.0")
|
| 10 |
-
DESCRIPTION = "Background noise dataset."
|
| 11 |
-
HOMEPAGE = "https://huggingface.co/datasets/sdialog/background"
|
| 12 |
-
LICENSE = "CC BY-NC-SA 4.0"
|
| 13 |
-
|
| 14 |
-
# Define features
|
| 15 |
-
features = Features({
|
| 16 |
-
"audio": Audio(sampling_rate=16000),
|
| 17 |
-
"file_path": Value("string"),
|
| 18 |
-
"label": Value("string"),
|
| 19 |
-
"description": Value("string"),
|
| 20 |
-
})
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
def dataset_generator():
|
| 24 |
-
csv_path = os.path.join(dataset_path, "metadata.csv")
|
| 25 |
-
if not os.path.exists(csv_path):
|
| 26 |
-
raise FileNotFoundError(
|
| 27 |
-
f"{csv_path} not found. Run create_metadata.py first."
|
| 28 |
-
)
|
| 29 |
-
|
| 30 |
-
with open(csv_path, "r", encoding="utf-8") as f:
|
| 31 |
-
reader = csv.DictReader(f)
|
| 32 |
-
for row in reader:
|
| 33 |
-
audio_path = row["audio"]
|
| 34 |
-
# Ensure the path is absolute for reading
|
| 35 |
-
# audio_path is relative to the dataset root
|
| 36 |
-
full_path = os.path.join(dataset_path, audio_path)
|
| 37 |
-
|
| 38 |
-
# Read audio bytes to ensure embedding
|
| 39 |
-
with open(full_path, "rb") as audio_file:
|
| 40 |
-
audio_bytes = audio_file.read()
|
| 41 |
-
|
| 42 |
-
yield {
|
| 43 |
-
"audio": {"path": None, "bytes": audio_bytes},
|
| 44 |
-
"file_path": audio_path,
|
| 45 |
-
"label": row["label"],
|
| 46 |
-
"description": row["description"]
|
| 47 |
-
}
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
print("Creating dataset from generator (embedding bytes)...")
|
| 51 |
-
ds = Dataset.from_generator(dataset_generator, features=features)
|
| 52 |
-
|
| 53 |
-
# Set dataset info
|
| 54 |
-
ds.info.version = VERSION
|
| 55 |
-
ds.info.description = DESCRIPTION
|
| 56 |
-
ds.info.homepage = HOMEPAGE
|
| 57 |
-
ds.info.license = LICENSE
|
| 58 |
-
|
| 59 |
-
print("Saving to Parquet...")
|
| 60 |
-
output_path = os.path.join(dataset_path, "data/train-00000-of-00001.parquet")
|
| 61 |
-
os.makedirs(os.path.dirname(output_path), exist_ok=True)
|
| 62 |
-
ds.to_parquet(output_path)
|
| 63 |
-
|
| 64 |
-
print(f"Saved to {output_path}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|