CoolFace
Apppublic

lspcloud/prolific-preferences-dynamic

sourceHugging Faceupdated 4mo agoView on Hugging Face
0likes
reject_submissions.py57 linesDownload Raw Back to root
1"""2Helper script to reject a submission.3 4Usage:5    python scripts/reject_submission.py \6        --repo lms-shape-preferences/results-preference-base \7        --token hf_... \8        --path json/worker123/submission456.json9 10This moves the file from json/ to rejected/ so the item gets re-assigned11to the next available participant.12"""13import argparse14import os15import tempfile16from huggingface_hub import HfApi17 18def reject_submission(repo_id: str, file_path: str, token: str) -> None:19    assert file_path.startswith("json/"), \20        f"Expected path starting with json/, got: {file_path}"21 22    api          = HfApi(token=token)23    rejected_path = file_path.replace("json/", "rejected/", 1)24 25    print(f"Downloading {file_path} ...")26    local = api.hf_hub_download(27        repo_id=repo_id,28        filename=file_path,29        repo_type="dataset",30        token=token,31    )32 33    print(f"Re-uploading to {rejected_path} ...")34    api.upload_file(35        path_or_fileobj=local,36        path_in_repo=rejected_path,37        repo_id=repo_id,38        repo_type="dataset",39    )40 41    print(f"Deleting {file_path} ...")42    api.delete_file(43        path_in_repo=file_path,44        repo_id=repo_id,45        repo_type="dataset",46    )47 48    print(f"Done. {file_path} → {rejected_path}")49    print("The item will be re-assigned within 5 minutes (cache TTL).")50 51if __name__ == "__main__":52    parser = argparse.ArgumentParser()53    parser.add_argument("--repo",  required=True)54    parser.add_argument("--token", default=os.getenv("HF_TOKEN"))55    parser.add_argument("--path",  required=True, help="e.g. json/worker123/submission456.json")56    args = parser.parse_args()57    reject_submission(args.repo, args.path, args.token)