Skip to content

Commit c137267

Browse files
authored
Allow to choose private for Trackio Spaces (#236)
1 parent c889370 commit c137267

3 files changed

Lines changed: 32 additions & 4 deletions

File tree

trackio/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def init(
5252
config: dict | None = None,
5353
resume: str = "never",
5454
settings: Any = None,
55+
private: bool | None = None,
5556
) -> Run:
5657
"""
5758
Creates a new Trackio project and returns a [`Run`] object.
@@ -89,6 +90,10 @@ def init(
8990
doesn't exist
9091
- `"allow"`: Resume the run if it exists, otherwise create a new run
9192
- `"never"`: Never resume a run, always create a new one
93+
private (`bool` or `None`, *optional*, defaults to `None`):
94+
Whether to make the Space private. If None (default), the repo will be
95+
public unless the organization's default is private. This value is ignored
96+
if the repo already exists.
9297
settings (`Any`, *optional*, defaults to `None`):
9398
Not used. Provided for compatibility with `wandb.init()`.
9499
@@ -133,7 +138,9 @@ def init(
133138
print(f"* Trackio metrics logged to: {TRACKIO_DIR}")
134139
utils.print_dashboard_instructions(project)
135140
else:
136-
deploy.create_space_if_not_exists(space_id, space_storage, dataset_id)
141+
deploy.create_space_if_not_exists(
142+
space_id, space_storage, dataset_id, private
143+
)
137144
print(
138145
f"* View dashboard by going to: {deploy.SPACE_URL.format(space_id=space_id)}"
139146
)

trackio/deploy.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def deploy_as_space(
4747
space_id: str,
4848
space_storage: huggingface_hub.SpaceStorage | None = None,
4949
dataset_id: str | None = None,
50+
private: bool | None = None,
5051
):
5152
if (
5253
os.getenv("SYSTEM") == "spaces"
@@ -60,6 +61,7 @@ def deploy_as_space(
6061
try:
6162
huggingface_hub.create_repo(
6263
space_id,
64+
private=private,
6365
space_sdk="gradio",
6466
space_storage=space_storage,
6567
repo_type="space",
@@ -71,6 +73,7 @@ def deploy_as_space(
7173
huggingface_hub.login(add_to_git_credential=False)
7274
huggingface_hub.create_repo(
7375
space_id,
76+
private=private,
7477
space_sdk="gradio",
7578
space_storage=space_storage,
7679
repo_type="space",
@@ -138,13 +141,17 @@ def create_space_if_not_exists(
138141
space_id: str,
139142
space_storage: huggingface_hub.SpaceStorage | None = None,
140143
dataset_id: str | None = None,
144+
private: bool | None = None,
141145
) -> None:
142146
"""
143147
Creates a new Hugging Face Space if it does not exist. If a dataset_id is provided, it will be added as a space variable.
144148
145149
Args:
146150
space_id: The ID of the Space to create.
147151
dataset_id: The ID of the Dataset to add to the Space.
152+
private: Whether to make the Space private. If None (default), the repo will be
153+
public unless the organization's default is private. This value is ignored if
154+
the repo already exists.
148155
"""
149156
if "/" not in space_id:
150157
raise ValueError(
@@ -175,7 +182,7 @@ def create_space_if_not_exists(
175182
raise ValueError(f"Failed to create Space: {e}")
176183

177184
print(f"* Creating new space: {SPACE_URL.format(space_id=space_id)}")
178-
deploy_as_space(space_id, space_storage, dataset_id)
185+
deploy_as_space(space_id, space_storage, dataset_id, private)
179186

180187

181188
def wait_until_space_exists(

trackio/imports.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ def import_csv(
1313
name: str | None = None,
1414
space_id: str | None = None,
1515
dataset_id: str | None = None,
16+
private: bool | None = None,
1617
) -> None:
1718
"""
1819
Imports a CSV file into a Trackio project. The CSV file must contain a `"step"`
@@ -50,6 +51,10 @@ def import_csv(
5051
SQLite database, unless a `space_id` is provided, in which case a Dataset
5152
will be automatically created with the same name as the Space but with the
5253
`"_dataset"` suffix.
54+
private (`bool` or `None`, *optional*, defaults to `None`):
55+
Whether to make the Space private. If None (default), the repo will be
56+
public unless the organization's default is private. This value is ignored
57+
if the repo already exists.
5358
"""
5459
if SQLiteStorage.get_runs(project):
5560
raise ValueError(
@@ -134,7 +139,9 @@ def import_csv(
134139
if space_id is None:
135140
utils.print_dashboard_instructions(project)
136141
else:
137-
deploy.create_space_if_not_exists(space_id=space_id, dataset_id=dataset_id)
142+
deploy.create_space_if_not_exists(
143+
space_id=space_id, dataset_id=dataset_id, private=private
144+
)
138145
deploy.wait_until_space_exists(space_id=space_id)
139146
deploy.upload_db_to_space(project=project, space_id=space_id)
140147
print(
@@ -148,6 +155,7 @@ def import_tf_events(
148155
name: str | None = None,
149156
space_id: str | None = None,
150157
dataset_id: str | None = None,
158+
private: bool | None = None,
151159
) -> None:
152160
"""
153161
Imports TensorFlow Events files from a directory into a Trackio project. Each
@@ -180,6 +188,10 @@ def import_tf_events(
180188
SQLite database, unless a `space_id` is provided, in which case a Dataset
181189
will be automatically created with the same name as the Space but with the
182190
`"_dataset"` suffix.
191+
private (`bool` or `None`, *optional*, defaults to `None`):
192+
Whether to make the Space private. If None (default), the repo will be
193+
public unless the organization's default is private. This value is ignored
194+
if the repo already exists.
183195
"""
184196
try:
185197
from tbparse import SummaryReader
@@ -280,7 +292,9 @@ def import_tf_events(
280292
if space_id is None:
281293
utils.print_dashboard_instructions(project)
282294
else:
283-
deploy.create_space_if_not_exists(space_id, dataset_id=dataset_id)
295+
deploy.create_space_if_not_exists(
296+
space_id, dataset_id=dataset_id, private=private
297+
)
284298
deploy.wait_until_space_exists(space_id)
285299
deploy.upload_db_to_space(project, space_id)
286300
print(

0 commit comments

Comments
 (0)