-
Notifications
You must be signed in to change notification settings - Fork 608
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: switch visibility with update_repo_settings #2537 #2541
Changes from 4 commits
de6794c
eae6028
5a376f3
5e3aef1
e169e96
edf03d2
06e31db
b06e6b4
e68280c
93d87a6
8b13d08
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -124,6 +124,7 @@ | |
SafetensorsParsingError, | ||
SafetensorsRepoMetadata, | ||
TensorInfo, | ||
_deprecate_method, | ||
hanouticelina marked this conversation as resolved.
Show resolved
Hide resolved
|
||
build_hf_headers, | ||
experimental, | ||
filter_repo_objects, | ||
|
@@ -3524,7 +3525,9 @@ def delete_repo( | |
if not missing_ok: | ||
raise | ||
|
||
@validate_hf_hub_args | ||
@_deprecate_method( | ||
version="0.29.x", message="This method will be removed in v0.29.x. Please use `update_repo_settings` instead." | ||
hanouticelina marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
def update_repo_visibility( | ||
self, | ||
repo_id: str, | ||
|
@@ -3533,7 +3536,7 @@ def update_repo_visibility( | |
token: Union[str, bool, None] = None, | ||
repo_type: Optional[str] = None, | ||
) -> Dict[str, bool]: | ||
"""Update the visibility setting of a repository. | ||
"""(Deprecated) Update the visibility setting of a repository. | ||
hanouticelina marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Args: | ||
repo_id (`str`, *optional*): | ||
|
@@ -3581,13 +3584,16 @@ def update_repo_settings( | |
self, | ||
repo_id: str, | ||
*, | ||
gated: Literal["auto", "manual", False] = False, | ||
gated: Optional[Literal["auto", "manual", False]] = False, | ||
private: Optional[bool] = False, | ||
hanouticelina marked this conversation as resolved.
Show resolved
Hide resolved
|
||
token: Union[str, bool, None] = None, | ||
repo_type: Optional[str] = None, | ||
) -> None: | ||
""" | ||
Update the gated settings of a repository. | ||
To give more control over how repos are used, the Hub allows repo authors to enable **access requests** for their repos. | ||
Update the settings of a repository, including gated access and visibility. | ||
|
||
To give more control over how repos are used, the Hub allows repo authors to enable | ||
access requests for their repos, and also to set the visibility of the repo to private. | ||
|
||
Args: | ||
repo_id (`str`): | ||
|
@@ -3597,6 +3603,8 @@ def update_repo_settings( | |
* "auto": The repository is gated, and access requests are automatically approved or denied based on predefined criteria. | ||
* "manual": The repository is gated, and access requests require manual approval. | ||
* False (default): The repository is not gated, and anyone can access it. | ||
hanouticelina marked this conversation as resolved.
Show resolved
Hide resolved
|
||
private (`bool`, *optional*, defaults to `False`): | ||
hanouticelina marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Whether the model repo should be private. | ||
token (`Union[str, bool, None]`, *optional*): | ||
A valid user access token (string). Defaults to the locally saved token, | ||
which is the recommended method for authentication (see | ||
|
@@ -3613,8 +3621,11 @@ def update_repo_settings( | |
If repo_type is not one of the values in constants.REPO_TYPES. | ||
[`~utils.HfHubHTTPError`]: | ||
If the request to the Hugging Face Hub API fails. | ||
[`~utils.RepositoryNotFoundError`] | ||
If the repository to download from cannot be found. This may be because it doesn't exist, | ||
or because it is set to `private` and you do not have access. | ||
""" | ||
if gated not in ["auto", "manual", False]: | ||
if gated is not None and gated not in ["auto", "manual", False]: | ||
hanouticelina marked this conversation as resolved.
Show resolved
Hide resolved
|
||
raise ValueError(f"Invalid gated status, must be one of 'auto', 'manual', or False. Got '{gated}'.") | ||
|
||
if repo_type not in constants.REPO_TYPES: | ||
|
@@ -3625,10 +3636,13 @@ def update_repo_settings( | |
# Build headers | ||
headers = self._build_hf_headers(token=token) | ||
|
||
# Preparing the JSON payload for the PUT request | ||
payload = {"gated": gated, "private": private} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would prepare the payload in 2 steps: payload: Dict = {}
if gated is not None:
if gated not in ["auto", "manual", False]:
raise ValueError(f"Invalid gated status, must be one of 'auto', 'manual', or False. Got '{gated}'.")
payload["gated"] = gated
if private is not None:
payload["private"] = private The advantage of doing so is that adding a new parameter will just be a matter of adding a new There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was planning on a similar approach, but I opted for the dictionary comprehension There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sometimes readibility / maintenance is more important than efficiency :) |
||
|
||
r = get_session().put( | ||
url=f"{self.endpoint}/api/{repo_type}s/{repo_id}/settings", | ||
headers=headers, | ||
json={"gated": gated}, | ||
json={key: value for key, value in payload.items() if value is not None}, | ||
) | ||
hf_raise_for_status(r) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would structure the documentation as such:
Setting a repo as gating and setting repo visibility is 2 different topics, even if related to accessibility. Usually either a repo is public, either private, either public and gated. Setting a repo as private and gated is possible but doesn't make sense.