#!/usr/bin/env python3 """ upload_kaggle.py — Upload the competition dataset to Kaggle Before running: 1. Create your Kaggle API token at https://www.kaggle.com/settings/account 2. Set up credentials: mkdir -p ~/.kaggle echo '{"username":"YOUR_USERNAME","key":"YOUR_API_KEY"}' > ~/.kaggle/kaggle.json chmod 600 ~/.kaggle/kaggle.json 3. Run: python upload_kaggle.py [--username YOUR_USERNAME] The dataset directory ./output/clip-pelatnas-p2/ will be uploaded. solution.csv is intentionally NOT included in the upload. """ import argparse import json import subprocess import sys from pathlib import Path DATASET_DIR = Path('./output/clip-pelatnas-p2') METADATA_FILE = DATASET_DIR / 'dataset-metadata.json' def check_kaggle_auth(): result = subprocess.run(['kaggle', 'whoami'], capture_output=True, text=True) if result.returncode != 0: print("ERROR: Kaggle authentication failed.") print("Set up ~/.kaggle/kaggle.json first.") print("See: https://www.kaggle.com/docs/api") sys.exit(1) username = result.stdout.strip() print(f"Authenticated as: {username}") return username def write_metadata(username: str, dataset_slug: str = 'clip-pelatnas-p2'): metadata = { "title": "CLIP Pelatnas P2 2026 — ARIA Multimodal Crisis", "id": f"{username}/{dataset_slug}", "licenses": [{"name": "other"}], } with open(METADATA_FILE, 'w') as f: json.dump(metadata, f, indent=2) print(f"Metadata written: {METADATA_FILE}") return metadata["id"] def upload(dataset_id: str): print(f"\nUploading dataset: {dataset_id}") print(f"Source directory: {DATASET_DIR.absolute()}") # Check if dataset already exists check = subprocess.run( ['kaggle', 'datasets', 'list', '--user', dataset_id.split('/')[0], '--search', 'clip-pelatnas-p2'], capture_output=True, text=True ) if 'clip-pelatnas-p2' in check.stdout: print("Dataset exists — creating a new version...") result = subprocess.run( ['kaggle', 'datasets', 'version', '-p', str(DATASET_DIR), '-m', 'Updated dataset v2', '--dir-mode', 'zip'], check=True ) else: print("Creating new dataset...") result = subprocess.run( ['kaggle', 'datasets', 'create', '-p', str(DATASET_DIR), '--dir-mode', 'zip'], check=True ) print(f"\nUpload complete: https://www.kaggle.com/datasets/{dataset_id}") def main(): parser = argparse.ArgumentParser(description='Upload competition dataset to Kaggle') parser.add_argument('--username', help='Kaggle username (optional, read from kaggle.json if not set)') args = parser.parse_args() if not DATASET_DIR.exists(): print(f"ERROR: Dataset directory not found: {DATASET_DIR}") print("Run prep_dataset.py first.") sys.exit(1) if (DATASET_DIR / 'solution.csv').exists(): print("WARNING: solution.csv found in dataset directory!") print("Remove it before uploading to prevent leakage.") sys.exit(1) username = check_kaggle_auth() if args.username: username = args.username dataset_id = write_metadata(username) upload(dataset_id) if __name__ == '__main__': main()