File size: 1,729 Bytes
0f4326e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"""
Helper script to reject a submission.

Usage:
    python scripts/reject_submission.py \
        --repo lms-shape-preferences/results-preference-base \
        --token hf_... \
        --path json/worker123/submission456.json

This moves the file from json/ to rejected/ so the item gets re-assigned
to the next available participant.
"""
import argparse
import os
import tempfile
from huggingface_hub import HfApi

def reject_submission(repo_id: str, file_path: str, token: str) -> None:
    assert file_path.startswith("json/"), \
        f"Expected path starting with json/, got: {file_path}"

    api          = HfApi(token=token)
    rejected_path = file_path.replace("json/", "rejected/", 1)

    print(f"Downloading {file_path} ...")
    local = api.hf_hub_download(
        repo_id=repo_id,
        filename=file_path,
        repo_type="dataset",
        token=token,
    )

    print(f"Re-uploading to {rejected_path} ...")
    api.upload_file(
        path_or_fileobj=local,
        path_in_repo=rejected_path,
        repo_id=repo_id,
        repo_type="dataset",
    )

    print(f"Deleting {file_path} ...")
    api.delete_file(
        path_in_repo=file_path,
        repo_id=repo_id,
        repo_type="dataset",
    )

    print(f"Done. {file_path}{rejected_path}")
    print("The item will be re-assigned within 5 minutes (cache TTL).")

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("--repo",  required=True)
    parser.add_argument("--token", default=os.getenv("HF_TOKEN"))
    parser.add_argument("--path",  required=True, help="e.g. json/worker123/submission456.json")
    args = parser.parse_args()
    reject_submission(args.repo, args.path, args.token)