[Feat] Endpoint configure gating on a repo
It's possible to add a gate to a repo programmatically. It's used in the Open LLM Leaderboard for instance (see slack -internal-). It can be done like this:
from huggingface_hub.utils import build_hf_headers, get_session, hf_raise_for_status
headers = build_hf_headers()
r = get_session().put(
url=f"https://huggingface.co/api/datasets/{repo_id}/settings",
headers=headers,
json={"gated": "auto"},
)
hf_raise_for_status(r)
Value can be "auto", "manual" or False.
It would be nice to add it as a new method in HfApi.
Yeah @Wauplin, this method to add a gate to repo programmatically can give more flexibility to adapt and access control for project needs, plus automating this process can streamline the workflow and reduce the manual effort for evaluation phase. Let me know if I'm going in the right direction??
Yes, that's exactly the goal! There are two main objectives:
- automate workflow when many repos are created by a script and needs to be gated (example: for the LLM Leaderboard)
- automate tests when you need a gated repo to test a feature
Alright, I got it. So how should we move ahead with this?
So what you'll need to do is:
- add a new method
update_repo_settings(self, repo_id: str, *, gated: Optional[Literal["auto", "manual", False]] = None, ...) - implement this method. You can take a look at
update_repo_visibilityas an example. - implement some tests in
tests/test_hf_api.py. You can check existing tests as an example - add a section in
docs/source/en/guides/repository.mdto mention this feature and how to use it
And that's it! If you have questions just let me know. You can always open a draft PR with only a subset of what I've mentioned above if you want a confirmation you are in the good direction.
Closed by https://github.com/huggingface/huggingface_hub/pull/2502. Thanks @WizKnight !