mrfakename commited on
Commit
e548b4b
·
verified ·
1 Parent(s): 5e918b3

Add durable source manifest builder

Browse files
Files changed (1) hide show
  1. build_manifest.py +60 -0
build_manifest.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # /// script
2
+ # requires-python = ">=3.10"
3
+ # dependencies = ["huggingface_hub>=1.0.0", "modelscope-hub>=0.2.0"]
4
+ # ///
5
+ """Create a durable, paginated file manifest for the Daimon-Infinity mirror."""
6
+
7
+ import json
8
+ import os
9
+ import time
10
+ from pathlib import Path
11
+
12
+ from huggingface_hub import HfApi
13
+ from modelscope_hub import HubApi
14
+
15
+ SOURCE = "daimonrobotics/Daimon-Infinity"
16
+ DESTINATION = "mrfakename/Daimon-Infinity"
17
+ MS_TOKEN = os.environ["MODELSCOPE_TOKEN"]
18
+ HF_TOKEN = os.environ["HF_TOKEN"]
19
+
20
+
21
+ def main():
22
+ source = HubApi(token=MS_TOKEN)
23
+ source.login(MS_TOKEN)
24
+ manifest = Path("/tmp/daimon-manifest.jsonl")
25
+ page = 1
26
+ count = 0
27
+ with manifest.open("w", encoding="utf-8") as output:
28
+ while True:
29
+ for attempt in range(8):
30
+ try:
31
+ response = source.legacy._request(
32
+ "GET", f"datasets/{SOURCE}/repo/tree",
33
+ params={"Revision": "master", "Recursive": "True", "PageNumber": page, "PageSize": 200},
34
+ )
35
+ data = source.legacy._json_data(response)
36
+ batch = data if isinstance(data, list) else data.get("Files", [])
37
+ break
38
+ except Exception:
39
+ source.login(MS_TOKEN)
40
+ time.sleep(min(60, 2**attempt))
41
+ else:
42
+ raise RuntimeError(f"Could not fetch ModelScope manifest page {page}")
43
+ for item in batch:
44
+ if (item.get("Type") or item.get("type")) != "tree":
45
+ output.write(json.dumps(item, ensure_ascii=False) + "\n")
46
+ count += 1
47
+ if page % 100 == 0:
48
+ print(f"page={page} files={count}", flush=True)
49
+ if len(batch) < 200:
50
+ break
51
+ page += 1
52
+ HfApi(token=HF_TOKEN).upload_file(
53
+ path_or_fileobj=str(manifest), path_in_repo=".mirror/manifest.jsonl",
54
+ repo_id=DESTINATION, repo_type="dataset", commit_message=f"Index {count} upstream files",
55
+ )
56
+ print(f"uploaded manifest: {count} files", flush=True)
57
+
58
+
59
+ if __name__ == "__main__":
60
+ main()