Neon-tech commited on
Commit
6045381
·
verified ·
1 Parent(s): fcaec83

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -14
app.py CHANGED
@@ -1,11 +1,9 @@
1
  import os
2
- import json
3
  import gc
4
  from pathlib import Path
5
 
6
- TOK_DIR = "/data/tokenized"
7
- OUT_DIR = "/data/ready"
8
- INDEX = "/data/index.json"
9
 
10
  CRAWL_MAP = {
11
  "2025-05": "fw-00001-of-00006.bin",
@@ -17,9 +15,10 @@ CRAWL_MAP = {
17
  }
18
 
19
  os.makedirs(OUT_DIR, exist_ok=True)
20
-
21
  print("Starting merge...")
22
- print(f"TOK_DIR contents: {list(Path(TOK_DIR).iterdir())[:5]}")
 
 
23
 
24
  for crawl_id, out_name in CRAWL_MAP.items():
25
  out_path = Path(OUT_DIR) / out_name
@@ -28,22 +27,23 @@ for crawl_id, out_name in CRAWL_MAP.items():
28
  continue
29
 
30
  shards = sorted(Path(TOK_DIR).glob(f"cc{crawl_id}_*.bin"))
31
- print(f" {crawl_id}: found {len(shards)} shards")
32
  if not shards:
33
  continue
34
 
35
  total_tokens = 0
36
  with open(out_path, "wb") as out_f:
37
  for shard in shards:
38
- with open(shard, "rb") as in_f:
39
- while True:
40
- chunk = in_f.read(4096)
41
- if not chunk:
42
- break
43
- out_f.write(chunk)
44
- total_tokens += len(chunk) // 2
45
  print(f" ✓ {shard.name}")
46
 
 
47
  print(f" ✓ {out_name} | {total_tokens:,} tokens")
48
 
 
49
  print("Done")
 
1
  import os
 
2
  import gc
3
  from pathlib import Path
4
 
5
+ TOK_DIR = "/data/tokenized"
6
+ OUT_DIR = "/data/ready"
 
7
 
8
  CRAWL_MAP = {
9
  "2025-05": "fw-00001-of-00006.bin",
 
15
  }
16
 
17
  os.makedirs(OUT_DIR, exist_ok=True)
 
18
  print("Starting merge...")
19
+ print(f"TOK_DIR sample: {list(Path(TOK_DIR).iterdir())[:5]}")
20
+
21
+ index = {}
22
 
23
  for crawl_id, out_name in CRAWL_MAP.items():
24
  out_path = Path(OUT_DIR) / out_name
 
27
  continue
28
 
29
  shards = sorted(Path(TOK_DIR).glob(f"cc{crawl_id}_*.bin"))
30
+ print(f" {crawl_id}: {len(shards)} shards")
31
  if not shards:
32
  continue
33
 
34
  total_tokens = 0
35
  with open(out_path, "wb") as out_f:
36
  for shard in shards:
37
+ data = shard.read_bytes()
38
+ out_f.write(data)
39
+ total_tokens += len(data) // 2
40
+ shard.unlink()
41
+ del data
42
+ gc.collect()
 
43
  print(f" ✓ {shard.name}")
44
 
45
+ index[out_name] = {"crawl": crawl_id, "total_tokens": total_tokens}
46
  print(f" ✓ {out_name} | {total_tokens:,} tokens")
47
 
48
+ Path("/data/index.json").write_text(__import__("json").dumps(index, indent=2))
49
  print("Done")