OpenTransformer commited on
Commit
a8de6dc
·
verified ·
1 Parent(s): 2a1aded

Upload source/combine_and_upload.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. source/combine_and_upload.py +66 -0
source/combine_and_upload.py ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os, glob, time
2
+ from huggingface_hub import HfApi
3
+
4
+ TOKEN = 'HF_TOKEN_REDACTED'
5
+ REPO = 'OpenTransformer/web-crawl-2026'
6
+ OUT = '/workspace/crawl_mega_20260323.jsonl.gz'
7
+
8
+ # Gather all .gz files that haven't been uploaded yet
9
+ files_to_combine = []
10
+
11
+ # Combined crawl files
12
+ for f in sorted(glob.glob('/workspace/combined_crawl_*.jsonl.gz')):
13
+ files_to_combine.append(f)
14
+
15
+ # Go chunks
16
+ for f in sorted(glob.glob('/workspace/scraped_data_go/*.jsonl.gz')):
17
+ files_to_combine.append(f)
18
+
19
+ # Rust staging
20
+ for f in sorted(glob.glob('/workspace/staging/*.jsonl.gz')):
21
+ files_to_combine.append(f)
22
+
23
+ print(f'Found {len(files_to_combine)} files to combine')
24
+ for f in files_to_combine:
25
+ sz = os.path.getsize(f) / (1024*1024)
26
+ print(f' {f}: {sz:.0f}MB')
27
+
28
+ # Concatenate gz files (gz files can be concatenated directly)
29
+ total = 0
30
+ with open(OUT, 'wb') as out:
31
+ for f in files_to_combine:
32
+ sz = os.path.getsize(f)
33
+ total += sz
34
+ print(f'Appending {f} ({sz/(1024*1024):.0f}MB)...')
35
+ with open(f, 'rb') as inp:
36
+ while True:
37
+ chunk = inp.read(8*1024*1024)
38
+ if not chunk:
39
+ break
40
+ out.write(chunk)
41
+
42
+ total_gb = total / (1024*1024*1024)
43
+ final_sz = os.path.getsize(OUT) / (1024*1024*1024)
44
+ print(f'Combined {len(files_to_combine)} files, total: {total_gb:.2f}GB, output: {final_sz:.2f}GB')
45
+
46
+ if final_sz < 0.1:
47
+ print('Output too small, skipping upload')
48
+ exit(1)
49
+
50
+ # Upload
51
+ print(f'Uploading {OUT} to {REPO}...')
52
+ api = HfApi(token=TOKEN)
53
+ api.upload_file(
54
+ path_or_fileobj=OUT,
55
+ path_in_repo=f'crawl/mega/crawl_mega_20260323.jsonl.gz',
56
+ repo_id=REPO,
57
+ repo_type='dataset',
58
+ )
59
+ print('Upload complete!')
60
+
61
+ # Clean up combined files after successful upload
62
+ os.remove(OUT)
63
+ for f in files_to_combine:
64
+ os.remove(f)
65
+ print(f'Removed {f}')
66
+ print('Cleanup done')