File size: 963 Bytes
19ee463
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""Delete the old numeric-named documents/<#>/ folders from the HF dataset."""

from __future__ import annotations

from huggingface_hub import HfApi

REPO = "trialdesignbench/source"


def main() -> None:
    api = HfApi()
    files = api.list_repo_files(REPO, repo_type="dataset")

    old = [
        f for f in files
        if f.startswith("documents/")
        and len(f.split("/")) >= 2
        and f.split("/")[1].isdigit()
    ]
    print(f"Found {len(old)} files under numeric folders. First 5:")
    for p in old[:5]:
        print(" ", p)

    if not old:
        return

    confirm = input(f"Delete all {len(old)} files? [y/N] ").strip().lower()
    if confirm != "y":
        print("Aborted.")
        return

    api.delete_files(
        delete_patterns=old,
        repo_id=REPO,
        repo_type="dataset",
        commit_message="Remove old numeric-named document folders",
    )
    print("Deleted.")


if __name__ == "__main__":
    main()