huggingface_hub icon indicating copy to clipboard operation
huggingface_hub copied to clipboard

[Feat] Endpoint configure gating on a repo

Open Wauplin opened this issue 1 year ago • 4 comments

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.

Wauplin avatar Aug 14 '24 09:08 Wauplin

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??

WizKnight avatar Aug 29 '24 22:08 WizKnight

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

Wauplin avatar Aug 30 '24 08:08 Wauplin

Alright, I got it. So how should we move ahead with this?

WizKnight avatar Aug 30 '24 09:08 WizKnight

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_visibility as 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.md to 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.

Wauplin avatar Aug 30 '24 11:08 Wauplin

Closed by https://github.com/huggingface/huggingface_hub/pull/2502. Thanks @WizKnight !

Wauplin avatar Sep 13 '24 08:09 Wauplin