fassabilf commited on
Commit
4a55ecf
·
verified ·
1 Parent(s): 3213443

Upload upload_kaggle.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. upload_kaggle.py +102 -0
upload_kaggle.py ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ upload_kaggle.py — Upload the competition dataset to Kaggle
4
+
5
+ Before running:
6
+ 1. Create your Kaggle API token at https://www.kaggle.com/settings/account
7
+ 2. Set up credentials:
8
+ mkdir -p ~/.kaggle
9
+ echo '{"username":"YOUR_USERNAME","key":"YOUR_API_KEY"}' > ~/.kaggle/kaggle.json
10
+ chmod 600 ~/.kaggle/kaggle.json
11
+ 3. Run: python upload_kaggle.py [--username YOUR_USERNAME]
12
+
13
+ The dataset directory ./output/clip-pelatnas-p2/ will be uploaded.
14
+ solution.csv is intentionally NOT included in the upload.
15
+ """
16
+
17
+ import argparse
18
+ import json
19
+ import subprocess
20
+ import sys
21
+ from pathlib import Path
22
+
23
+ DATASET_DIR = Path('./output/clip-pelatnas-p2')
24
+ METADATA_FILE = DATASET_DIR / 'dataset-metadata.json'
25
+
26
+
27
+ def check_kaggle_auth():
28
+ result = subprocess.run(['kaggle', 'whoami'], capture_output=True, text=True)
29
+ if result.returncode != 0:
30
+ print("ERROR: Kaggle authentication failed.")
31
+ print("Set up ~/.kaggle/kaggle.json first.")
32
+ print("See: https://www.kaggle.com/docs/api")
33
+ sys.exit(1)
34
+ username = result.stdout.strip()
35
+ print(f"Authenticated as: {username}")
36
+ return username
37
+
38
+
39
+ def write_metadata(username: str, dataset_slug: str = 'clip-pelatnas-p2'):
40
+ metadata = {
41
+ "title": "CLIP Pelatnas P2 2026 — ARIA Multimodal Crisis",
42
+ "id": f"{username}/{dataset_slug}",
43
+ "licenses": [{"name": "other"}],
44
+ }
45
+ with open(METADATA_FILE, 'w') as f:
46
+ json.dump(metadata, f, indent=2)
47
+ print(f"Metadata written: {METADATA_FILE}")
48
+ return metadata["id"]
49
+
50
+
51
+ def upload(dataset_id: str):
52
+ print(f"\nUploading dataset: {dataset_id}")
53
+ print(f"Source directory: {DATASET_DIR.absolute()}")
54
+
55
+ # Check if dataset already exists
56
+ check = subprocess.run(
57
+ ['kaggle', 'datasets', 'list', '--user', dataset_id.split('/')[0], '--search', 'clip-pelatnas-p2'],
58
+ capture_output=True, text=True
59
+ )
60
+
61
+ if 'clip-pelatnas-p2' in check.stdout:
62
+ print("Dataset exists — creating a new version...")
63
+ result = subprocess.run(
64
+ ['kaggle', 'datasets', 'version', '-p', str(DATASET_DIR),
65
+ '-m', 'Updated dataset v2', '--dir-mode', 'zip'],
66
+ check=True
67
+ )
68
+ else:
69
+ print("Creating new dataset...")
70
+ result = subprocess.run(
71
+ ['kaggle', 'datasets', 'create', '-p', str(DATASET_DIR), '--dir-mode', 'zip'],
72
+ check=True
73
+ )
74
+
75
+ print(f"\nUpload complete: https://www.kaggle.com/datasets/{dataset_id}")
76
+
77
+
78
+ def main():
79
+ parser = argparse.ArgumentParser(description='Upload competition dataset to Kaggle')
80
+ parser.add_argument('--username', help='Kaggle username (optional, read from kaggle.json if not set)')
81
+ args = parser.parse_args()
82
+
83
+ if not DATASET_DIR.exists():
84
+ print(f"ERROR: Dataset directory not found: {DATASET_DIR}")
85
+ print("Run prep_dataset.py first.")
86
+ sys.exit(1)
87
+
88
+ if (DATASET_DIR / 'solution.csv').exists():
89
+ print("WARNING: solution.csv found in dataset directory!")
90
+ print("Remove it before uploading to prevent leakage.")
91
+ sys.exit(1)
92
+
93
+ username = check_kaggle_auth()
94
+ if args.username:
95
+ username = args.username
96
+
97
+ dataset_id = write_metadata(username)
98
+ upload(dataset_id)
99
+
100
+
101
+ if __name__ == '__main__':
102
+ main()