| |
| """ |
| 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.") |