| """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() | |