| |
| |
|
|
| from pathlib import Path |
| from concurrent.futures import ThreadPoolExecutor, as_completed |
| from modelscope.hub.api import HubApi |
|
|
| |
| repo_id = "cangyeone/SeismicX-Cont" |
| repo_type = "dataset" |
|
|
| max_workers = 16 |
|
|
| files_to_upload = [ |
| ("data/hdf5/continuous_waveform_usa_20190701.h5", "data/hdf5/continuous_waveform_usa_20190701.h5"), |
| ("data/hdf5/continuous_waveform_usa_20190702.h5", "data/hdf5/continuous_waveform_usa_20190702.h5"), |
| ("data/hdf5/continuous_waveform_usa_20190703.h5", "data/hdf5/continuous_waveform_usa_20190703.h5"), |
| ("data/hdf5/continuous_waveform_usa_20190704.h5", "data/hdf5/continuous_waveform_usa_20190704.h5"), |
| ("data/hdf5/continuous_waveform_usa_20190705.h5", "data/hdf5/continuous_waveform_usa_20190705.h5"), |
| ("data/hdf5/continuous_waveform_usa_20190706.h5", "data/hdf5/continuous_waveform_usa_20190706.h5"), |
| ("data/hdf5/continuous_waveform_usa_20190707.h5", "data/hdf5/continuous_waveform_usa_20190707.h5"), |
| ("data/hdf5/continuous_waveform_usa_20211108.h5", "data/hdf5/continuous_waveform_usa_20211108.h5"), |
| ("data/hdf5/continuous_waveform_usa_20211109.h5", "data/hdf5/continuous_waveform_usa_20211109.h5"), |
| ("data/hdf5/continuous_waveform_usa_20211110.h5", "data/hdf5/continuous_waveform_usa_20211110.h5"), |
| ("data/hdf5/continuous_waveform_usa_20211111.h5", "data/hdf5/continuous_waveform_usa_20211111.h5"), |
| ("data/hdf5/continuous_waveform_usa_20211112.h5", "data/hdf5/continuous_waveform_usa_20211112.h5"), |
| ("data/hdf5/continuous_waveform_usa_20211113.h5", "data/hdf5/continuous_waveform_usa_20211113.h5"), |
| ("data/hdf5/continuous_waveform_usa_20211114.h5", "data/hdf5/continuous_waveform_usa_20211114.h5"), |
|
|
| ("data/index/waveform_index.sqlite", "data/index/waveform_index.sqlite"), |
|
|
| ("data/label/annotations_download_from_iris.json", "data/label/annotations_download_from_iris.json"), |
| ("data/label/annotations_for_continuous_hdf5.json", "data/label/annotations_for_continuous_hdf5.json"), |
|
|
| ("data/picks/output.jsonl", "data/picks/output.jsonl"), |
| ] |
| |
|
|
|
|
| def upload_one(item): |
| local_path, remote_path = item |
| p = Path(local_path) |
|
|
| if not p.exists(): |
| return False, local_path, f"本地文件不存在: {local_path}" |
|
|
| api = HubApi() |
|
|
| print(f"[UPLOAD START] {local_path} -> {repo_id}/{remote_path}") |
|
|
| try: |
| api.upload_file( |
| path_or_fileobj=str(p), |
| path_in_repo=remote_path, |
| repo_id=repo_id, |
| repo_type=repo_type, |
| commit_message=f"Upload {remote_path}", |
| ) |
| return True, local_path, "OK" |
|
|
| except Exception as e: |
| return False, local_path, str(e) |
|
|
|
|
| def main(): |
| api = HubApi() |
|
|
| |
| |
|
|
| try: |
| api.create_repo(repo_id=repo_id, repo_type=repo_type) |
| print(f"[INFO] Repo created: {repo_id}") |
| except Exception as e: |
| print(f"[INFO] Repo may already exist: {repo_id}") |
| print(f" {e}") |
|
|
| print(f"[INFO] Total files: {len(files_to_upload)}") |
| print(f"[INFO] max_workers = {max_workers}") |
|
|
| failed = [] |
|
|
| with ThreadPoolExecutor(max_workers=max_workers) as executor: |
| futures = { |
| executor.submit(upload_one, item): item |
| for item in files_to_upload |
| } |
|
|
| for future in as_completed(futures): |
| ok, local_path, msg = future.result() |
|
|
| if ok: |
| print(f"[DONE] {local_path}") |
| else: |
| print(f"[FAILED] {local_path}") |
| print(f" {msg}") |
| failed.append((local_path, msg)) |
|
|
| print("\n========== SUMMARY ==========") |
| print(f"success: {len(files_to_upload) - len(failed)}") |
| print(f"failed : {len(failed)}") |
|
|
| if failed: |
| print("\n失败文件:") |
| for local_path, msg in failed: |
| print(f"- {local_path}: {msg}") |
| else: |
| print("全部上传完成。") |
|
|
|
|
| if __name__ == "__main__": |
| main() |