OpenTransformer commited on
Commit
f06f7f7
·
verified ·
1 Parent(s): 569f763

Upload source/emergency_upload.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. source/emergency_upload.py +53 -0
source/emergency_upload.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import subprocess, os, time, glob
2
+
3
+ REPO = "OpenTransformer/web-crawl-2026"
4
+ files = []
5
+
6
+ # Get all chunks - upload finished ones first, then active ones (copy-then-upload)
7
+ for pattern in ["/workspace/scraped_data_rust/*.jsonl.gz", "/workspace/scraped_data_go/*.jsonl.gz", "/workspace/scraped_data/*.jsonl.gz"]:
8
+ files.extend(glob.glob(pattern))
9
+
10
+ print(f"Found {len(files)} files to upload")
11
+
12
+ for f in sorted(files, key=os.path.getsize, reverse=True):
13
+ size_mb = os.path.getsize(f) / 1024 / 1024
14
+ basename = os.path.basename(f)
15
+
16
+ # For active files, copy first so we upload a consistent snapshot
17
+ mtime_age = time.time() - os.path.getmtime(f)
18
+ if mtime_age < 300: # modified in last 5 min = still active
19
+ print(f"ACTIVE: {basename} ({size_mb:.0f}MB, {mtime_age:.0f}s ago) - copying snapshot...")
20
+ snap = f"/tmp/snap_{basename}"
21
+ os.system(f"cp {f} {snap}")
22
+ upload_path = snap
23
+ else:
24
+ print(f"DONE: {basename} ({size_mb:.0f}MB)")
25
+ upload_path = f
26
+
27
+ # Determine HF subfolder
28
+ if "rust" in f:
29
+ hf_path = f"data/{basename}"
30
+ elif "go" in f:
31
+ hf_path = f"data/{basename}"
32
+ else:
33
+ hf_path = f"data/{basename}"
34
+
35
+ print(f" Uploading {hf_path}...")
36
+ from huggingface_hub import HfApi
37
+ api = HfApi()
38
+ try:
39
+ api.upload_file(
40
+ path_or_fileobj=upload_path,
41
+ path_in_repo=hf_path,
42
+ repo_id=REPO,
43
+ repo_type="dataset",
44
+ )
45
+ print(f" OK: {hf_path}")
46
+ except Exception as e:
47
+ print(f" FAIL: {e}")
48
+
49
+ # Clean up snapshot
50
+ if upload_path.startswith("/tmp/snap_"):
51
+ os.remove(upload_path)
52
+
53
+ print("ALL DONE")