| |
| """ |
| Upload the wine text dataset to HuggingFace Hub. |
| |
| Prerequisites: |
| 1. Install required packages: pip install datasets huggingface_hub pyarrow |
| 2. Login to HF Hub: huggingface-cli login |
| 3. Replace YOUR_USERNAME with your actual HF username |
| |
| Usage: |
| python upload_to_hf.py --username YOUR_USERNAME [--private] |
| """ |
|
|
| import argparse |
| import pandas as pd |
| from datasets import Dataset, Features, Value |
| from huggingface_hub import HfApi |
| import os |
|
|
| def create_dataset_features(): |
| """Define the dataset schema.""" |
| return Features({ |
| "id": Value("string"), |
| "name": Value("string"), |
| "description": Value("string"), |
| "price": Value("float32"), |
| "category": Value("string"), |
| "region": Value("string"), |
| "image_id": Value("string"), |
| }) |
|
|
| def load_and_prepare_dataset(parquet_file="wine_text_126k.parquet"): |
| """Load the parquet file and create a HuggingFace Dataset.""" |
|
|
| print(f"Loading dataset from {parquet_file}...") |
| df = pd.read_parquet(parquet_file) |
|
|
| |
| print(f"Dataset shape: {df.shape}") |
| print(f"Columns: {list(df.columns)}") |
|
|
| |
| missing = df.isnull().sum() |
| if missing.any(): |
| print("Warning: Missing values found:") |
| print(missing[missing > 0]) |
| else: |
| print("✅ No missing values found") |
|
|
| |
| features = create_dataset_features() |
| dataset = Dataset.from_pandas(df, features=features, preserve_index=False) |
|
|
| print(f"✅ Created HuggingFace Dataset with {len(dataset):,} records") |
| return dataset |
|
|
| def upload_dataset(dataset, username, repo_name="wine-text-126k", private=False): |
| """Upload the dataset to HuggingFace Hub.""" |
|
|
| full_repo_name = f"{username}/{repo_name}" |
|
|
| print(f"\n🚀 Uploading to HuggingFace Hub: {full_repo_name}") |
| print(f"Privacy: {'Private' if private else 'Public'}") |
|
|
| try: |
| |
| api = HfApi() |
| try: |
| api.create_repo( |
| repo_id=full_repo_name, |
| repo_type="dataset", |
| private=private |
| ) |
| print(f"✅ Created repository: {full_repo_name}") |
| except Exception as e: |
| if "already exists" in str(e).lower(): |
| print(f"ℹ️ Repository already exists: {full_repo_name}") |
| else: |
| print(f"⚠️ Repository creation warning: {e}") |
|
|
| |
| print("📤 Uploading dataset files...") |
| dataset.push_to_hub( |
| full_repo_name, |
| private=private, |
| commit_message="Initial upload of wine text dataset" |
| ) |
|
|
| print(f"\n🎉 Upload completed successfully!") |
| print(f"🔗 Dataset URL: https://huggingface.co/datasets/{full_repo_name}") |
| print(f"\n📖 Usage:") |
| print(f'from datasets import load_dataset') |
| print(f'dataset = load_dataset("{full_repo_name}")') |
|
|
| return True |
|
|
| except Exception as e: |
| print(f"❌ Upload failed: {e}") |
| print("\nTroubleshooting:") |
| print("1. Make sure you're logged in: huggingface-cli login") |
| print("2. Check your internet connection") |
| print("3. Verify the username is correct") |
| print("4. Ensure you have write permissions") |
| return False |
|
|
| def main(): |
| parser = argparse.ArgumentParser(description="Upload wine dataset to HuggingFace Hub") |
| parser.add_argument("--username", required=True, help="Your HuggingFace username") |
| parser.add_argument("--private", action="store_true", help="Make the dataset private") |
| parser.add_argument("--parquet-file", default="wine_text_126k.parquet", |
| help="Path to the parquet file") |
|
|
| args = parser.parse_args() |
|
|
| |
| if not os.path.exists(args.parquet_file): |
| print(f"❌ Error: Parquet file not found: {args.parquet_file}") |
| print("Make sure you're running this script from the wine-text-126k directory") |
| return |
|
|
| print("🍷 Wine Text Dataset - HuggingFace Upload") |
| print("=" * 50) |
|
|
| |
| dataset = load_and_prepare_dataset(args.parquet_file) |
|
|
| |
| success = upload_dataset(dataset, args.username, private=args.private) |
|
|
| if success: |
| print("\n✅ All done! Your dataset is now live on HuggingFace Hub.") |
| print("Don't forget to update the README.md with your actual username!") |
| else: |
| print("\n❌ Upload failed. Please check the error messages above.") |
|
|
| if __name__ == "__main__": |
| main() |