cangyeone commited on
Commit
f3d5bd3
·
verified ·
1 Parent(s): 205373f

Upload scripts/upload_files_to_hf.py

Browse files
Files changed (1) hide show
  1. scripts/upload_files_to_hf.py +107 -0
scripts/upload_files_to_hf.py ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+
4
+ from pathlib import Path
5
+ from concurrent.futures import ThreadPoolExecutor, as_completed
6
+ from huggingface_hub import HfApi, create_repo
7
+
8
+ # ========= 配置区 =========
9
+ repo_id = "cangyeone/SeismicX-Cont"
10
+ repo_type = "dataset"
11
+
12
+ max_workers = 8 # 30GB 大文件建议 2;网络很好可改成 3
13
+
14
+ files_to_upload = [
15
+ ("data/hdf5/continuous_waveform_usa_20190701.h5", "data/hdf5/continuous_waveform_usa_20190701.h5"),
16
+ ("data/hdf5/continuous_waveform_usa_20190702.h5", "data/hdf5/continuous_waveform_usa_20190702.h5"),
17
+ ("data/hdf5/continuous_waveform_usa_20190703.h5", "data/hdf5/continuous_waveform_usa_20190703.h5"),
18
+ ("data/hdf5/continuous_waveform_usa_20190704.h5", "data/hdf5/continuous_waveform_usa_20190704.h5"),
19
+ ("data/hdf5/continuous_waveform_usa_20190705.h5", "data/hdf5/continuous_waveform_usa_20190705.h5"),
20
+ ("data/hdf5/continuous_waveform_usa_20190706.h5", "data/hdf5/continuous_waveform_usa_20190706.h5"),
21
+ ("data/hdf5/continuous_waveform_usa_20190707.h5", "data/hdf5/continuous_waveform_usa_20190707.h5"),
22
+ ("data/hdf5/continuous_waveform_usa_20211108.h5", "data/hdf5/continuous_waveform_usa_20211108.h5"),
23
+ ("data/hdf5/continuous_waveform_usa_20211109.h5", "data/hdf5/continuous_waveform_usa_20211109.h5"),
24
+ ("data/hdf5/continuous_waveform_usa_20211110.h5", "data/hdf5/continuous_waveform_usa_20211110.h5"),
25
+ ("data/hdf5/continuous_waveform_usa_20211111.h5", "data/hdf5/continuous_waveform_usa_20211111.h5"),
26
+ ("data/hdf5/continuous_waveform_usa_20211112.h5", "data/hdf5/continuous_waveform_usa_20211112.h5"),
27
+ ("data/hdf5/continuous_waveform_usa_20211113.h5", "data/hdf5/continuous_waveform_usa_20211113.h5"),
28
+ ("data/hdf5/continuous_waveform_usa_20211114.h5", "data/hdf5/continuous_waveform_usa_20211114.h5"),
29
+
30
+ ("data/index/waveform_index.sqlite", "data/index/waveform_index.sqlite"),
31
+
32
+ ("data/label/annotations_download_from_iris.json", "data/label/annotations_download_from_iris.json"),
33
+ ("data/label/annotations_for_continuous_hdf5.json", "data/label/annotations_for_continuous_hdf5.json"),
34
+
35
+ ("data/picks/output.jsonl", "data/picks/output.jsonl"),
36
+ ]
37
+ # =========================
38
+
39
+
40
+ def upload_one(item):
41
+ local_path, remote_path = item
42
+ p = Path(local_path)
43
+
44
+ if not p.exists():
45
+ return False, local_path, f"本地文件不存在: {local_path}"
46
+
47
+ api = HfApi()
48
+
49
+ print(f"[UPLOAD START] {local_path} -> {repo_id}/{remote_path}")
50
+
51
+ try:
52
+ api.upload_file(
53
+ path_or_fileobj=str(p),
54
+ path_in_repo=remote_path,
55
+ repo_id=repo_id,
56
+ repo_type=repo_type,
57
+ commit_message=f"Upload {remote_path}",
58
+ )
59
+ return True, local_path, "OK"
60
+
61
+ except Exception as e:
62
+ return False, local_path, str(e)
63
+
64
+
65
+ def main():
66
+ create_repo(
67
+ repo_id=repo_id,
68
+ repo_type=repo_type,
69
+ exist_ok=True,
70
+ )
71
+
72
+ print(f"[INFO] Repo ready: {repo_id}")
73
+ print(f"[INFO] Total files: {len(files_to_upload)}")
74
+ print(f"[INFO] max_workers = {max_workers}")
75
+
76
+ failed = []
77
+
78
+ with ThreadPoolExecutor(max_workers=max_workers) as executor:
79
+ futures = {
80
+ executor.submit(upload_one, item): item
81
+ for item in files_to_upload
82
+ }
83
+
84
+ for future in as_completed(futures):
85
+ ok, local_path, msg = future.result()
86
+
87
+ if ok:
88
+ print(f"[DONE] {local_path}")
89
+ else:
90
+ print(f"[FAILED] {local_path}")
91
+ print(f" {msg}")
92
+ failed.append((local_path, msg))
93
+
94
+ print("\n========== SUMMARY ==========")
95
+ print(f"success: {len(files_to_upload) - len(failed)}")
96
+ print(f"failed : {len(failed)}")
97
+
98
+ if failed:
99
+ print("\n失败文件:")
100
+ for local_path, msg in failed:
101
+ print(f"- {local_path}: {msg}")
102
+ else:
103
+ print("全部上传完成。")
104
+
105
+
106
+ if __name__ == "__main__":
107
+ main()