# /// script # requires-python = ">=3.10" # dependencies = ["huggingface_hub>=1.0.0", "modelscope-hub>=0.2.0"] # /// """Create a durable, paginated file manifest for the Daimon-Infinity mirror.""" import json import os import time from pathlib import Path from huggingface_hub import HfApi from modelscope_hub import HubApi SOURCE = "daimonrobotics/Daimon-Infinity" DESTINATION = "mrfakename/Daimon-Infinity" MS_TOKEN = os.environ["MODELSCOPE_TOKEN"] HF_TOKEN = os.environ["HF_TOKEN"] def main(): source = HubApi(token=MS_TOKEN) source.login(MS_TOKEN) manifest = Path("/tmp/daimon-manifest.jsonl") page = 1 count = 0 with manifest.open("w", encoding="utf-8") as output: while True: for attempt in range(8): try: response = source.legacy._request( "GET", f"datasets/{SOURCE}/repo/tree", params={"Revision": "master", "Recursive": "True", "PageNumber": page, "PageSize": 200}, ) data = source.legacy._json_data(response) batch = data if isinstance(data, list) else data.get("Files", []) break except Exception: source.login(MS_TOKEN) time.sleep(min(60, 2**attempt)) else: raise RuntimeError(f"Could not fetch ModelScope manifest page {page}") for item in batch: if (item.get("Type") or item.get("type")) != "tree": output.write(json.dumps(item, ensure_ascii=False) + "\n") count += 1 if page % 100 == 0: print(f"page={page} files={count}", flush=True) if len(batch) < 200: break page += 1 HfApi(token=HF_TOKEN).upload_file( path_or_fileobj=str(manifest), path_in_repo=".mirror/manifest.jsonl", repo_id=DESTINATION, repo_type="dataset", commit_message=f"Index {count} upstream files", ) print(f"uploaded manifest: {count} files", flush=True) if __name__ == "__main__": main()