|
|
|
|
|
""" |
|
|
Test the wine dataset before uploading to HuggingFace. |
|
|
This script validates the data quality and structure. |
|
|
""" |
|
|
|
|
|
import pandas as pd |
|
|
from datasets import Dataset, Features, Value |
|
|
|
|
|
def test_dataset(): |
|
|
"""Test the dataset structure and quality.""" |
|
|
|
|
|
print("π· Testing Wine Text Dataset") |
|
|
print("=" * 40) |
|
|
|
|
|
|
|
|
print("π Loading dataset...") |
|
|
df = pd.read_parquet("wine_text_126k.parquet") |
|
|
|
|
|
|
|
|
print(f"β
Dataset loaded: {len(df):,} records") |
|
|
print(f"β
Columns: {list(df.columns)}") |
|
|
|
|
|
|
|
|
expected_columns = ['id', 'name', 'description', 'price', 'category', 'region', 'image_id'] |
|
|
if list(df.columns) == expected_columns: |
|
|
print("β
Schema matches expected structure") |
|
|
else: |
|
|
print(f"β Schema mismatch. Expected: {expected_columns}") |
|
|
return False |
|
|
|
|
|
|
|
|
print("\nπ Data Quality Report:") |
|
|
|
|
|
|
|
|
missing = df.isnull().sum() |
|
|
if missing.any(): |
|
|
print("β Missing values found:") |
|
|
for col, count in missing.items(): |
|
|
if count > 0: |
|
|
print(f" {col}: {count:,} missing") |
|
|
return False |
|
|
else: |
|
|
print("β
No missing values") |
|
|
|
|
|
|
|
|
id_pattern_valid = df['id'].str.match(r'^wine_\d{6}$').all() |
|
|
if id_pattern_valid: |
|
|
print("β
ID format is correct (wine_XXXXXX)") |
|
|
else: |
|
|
print("β Invalid ID format found") |
|
|
return False |
|
|
|
|
|
|
|
|
price_min, price_max = df['price'].min(), df['price'].max() |
|
|
print(f"β
Price range: ${price_min:.2f} - ${price_max:.2f}") |
|
|
|
|
|
|
|
|
categories = df['category'].value_counts() |
|
|
print(f"β
Wine categories ({len(categories)} types):") |
|
|
for cat, count in categories.head().items(): |
|
|
print(f" {cat}: {count:,}") |
|
|
|
|
|
|
|
|
regions = df['region'].value_counts() |
|
|
print(f"β
Regions ({len(regions)} types):") |
|
|
for region, count in regions.items(): |
|
|
print(f" {region}: {count:,}") |
|
|
|
|
|
|
|
|
print("\nπ€ Testing HuggingFace Dataset creation...") |
|
|
try: |
|
|
features = Features({ |
|
|
"id": Value("string"), |
|
|
"name": Value("string"), |
|
|
"description": Value("string"), |
|
|
"price": Value("float32"), |
|
|
"category": Value("string"), |
|
|
"region": Value("string"), |
|
|
"image_id": Value("string"), |
|
|
}) |
|
|
|
|
|
dataset = Dataset.from_pandas(df, features=features, preserve_index=False) |
|
|
print(f"β
HuggingFace Dataset created successfully") |
|
|
print(f"β
Dataset info: {dataset}") |
|
|
|
|
|
|
|
|
print("\nπ Sample records:") |
|
|
for i in range(min(3, len(dataset))): |
|
|
record = dataset[i] |
|
|
print(f" ID: {record['id']}") |
|
|
print(f" Name: {record['name'][:50]}...") |
|
|
print(f" Price: ${record['price']:.2f}") |
|
|
print(f" Category: {record['category']}") |
|
|
print() |
|
|
|
|
|
return True |
|
|
|
|
|
except Exception as e: |
|
|
print(f"β HuggingFace Dataset creation failed: {e}") |
|
|
return False |
|
|
|
|
|
if __name__ == "__main__": |
|
|
success = test_dataset() |
|
|
|
|
|
if success: |
|
|
print("π All tests passed! Dataset is ready for upload.") |
|
|
print("\nπ€ To upload to HuggingFace Hub:") |
|
|
print("1. pip install datasets huggingface_hub pyarrow") |
|
|
print("2. huggingface-cli login") |
|
|
print("3. python upload_to_hf.py --username YOUR_USERNAME") |
|
|
else: |
|
|
print("β Tests failed. Please fix the issues above before uploading.") |