|
|
|
|
|
|
|
|
import json |
|
|
import os |
|
|
from pathlib import Path |
|
|
from datasets import Dataset, Audio |
|
|
|
|
|
|
|
|
def test_final_structure(): |
|
|
"""Test the final dataset structure for HF compatibility""" |
|
|
|
|
|
print("Testing final dataset structure...") |
|
|
print("=" * 50) |
|
|
|
|
|
|
|
|
files_to_check = [ |
|
|
"metadata.jsonl", |
|
|
"audio/xin_chao.mp3", |
|
|
"audio/cam_on.mp3", |
|
|
"audio/viet_nam.mp3" |
|
|
] |
|
|
|
|
|
print("1. Checking file structure:") |
|
|
for file_path in files_to_check: |
|
|
if os.path.exists(file_path): |
|
|
print(f" β {file_path}") |
|
|
else: |
|
|
print(f" β {file_path} - MISSING") |
|
|
return False |
|
|
|
|
|
|
|
|
print("\n2. Loading metadata.jsonl:") |
|
|
try: |
|
|
records = [] |
|
|
with open("metadata.jsonl", "r", encoding="utf-8") as f: |
|
|
for line_num, line in enumerate(f, 1): |
|
|
try: |
|
|
record = json.loads(line) |
|
|
records.append(record) |
|
|
except json.JSONDecodeError as e: |
|
|
print(f" β Line {line_num}: Invalid JSON - {e}") |
|
|
return False |
|
|
|
|
|
print(f" β Loaded {len(records)} records") |
|
|
|
|
|
|
|
|
required_fields = ["file_name", "word", "ipa"] |
|
|
for i, record in enumerate(records[:3], 1): |
|
|
missing_fields = [field for field in required_fields if field not in record] |
|
|
if missing_fields: |
|
|
print(f" β Record {i} missing fields: {missing_fields}") |
|
|
return False |
|
|
|
|
|
print(f" β All records have required fields: {required_fields}") |
|
|
|
|
|
except Exception as e: |
|
|
print(f" β Error loading metadata: {e}") |
|
|
return False |
|
|
|
|
|
|
|
|
print("\n3. Testing with datasets library:") |
|
|
try: |
|
|
dataset = Dataset.from_list(records) |
|
|
dataset = dataset.cast_column("file_name", Audio(decode=False)) |
|
|
|
|
|
print(f" β Dataset created successfully") |
|
|
print(f" β Features: {dataset.features}") |
|
|
print(f" β Number of examples: {len(dataset)}") |
|
|
|
|
|
|
|
|
first_example = dataset[0] |
|
|
print(f" β First example loaded: {first_example['word']} ({first_example['ipa']})") |
|
|
|
|
|
except Exception as e: |
|
|
print(f" β Error with datasets library: {e}") |
|
|
return False |
|
|
|
|
|
print("\n4. Summary:") |
|
|
print(" β Files in root directory") |
|
|
print(" β metadata.jsonl with file_name column") |
|
|
print(" β Audio files in audio/ subdirectory") |
|
|
print(" β Compatible with datasets library") |
|
|
print(" β Ready for Hugging Face Dataset Viewer") |
|
|
|
|
|
return True |
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
success = test_final_structure() |
|
|
|
|
|
if success: |
|
|
print("\nπ Dataset structure is correct and ready for upload!") |
|
|
else: |
|
|
print("\nβ Dataset structure needs fixes") |