Skip to content

Commit 72ce737

Browse files
authored
fixes to support video privacy mode (#410)
1 parent 4aadb82 commit 72ce737

File tree

6 files changed

+33
-15
lines changed

6 files changed

+33
-15
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

88

9+
## [0.16.9](https://github.com/scaleapi/nucleus-python-client/releases/tag/v0.16.9) - 2023-11-17
10+
11+
### Fixes
12+
13+
- Minor fixes to video scene upload on privacy moce
14+
915
## [0.16.8](https://github.com/scaleapi/nucleus-python-client/releases/tag/v0.16.8) - 2023-11-16
1016

1117
### Added

nucleus/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@
152152
TYPE_KEY = "type"
153153
UPDATED_ITEMS = "updated_items"
154154
UPDATE_KEY = "update"
155+
# avoid using this, as it will be deprecated
156+
UPLOAD_TO_SCALE_KEY = "upload_to_scale"
155157
URL_KEY = "url"
156158
VERTICES_KEY = "vertices"
157159
VIDEO_LOCATION_KEY = "video_location"

nucleus/dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,6 @@ def _append_video_scenes(
785785
update: Optional[bool] = False,
786786
asynchronous: Optional[bool] = False,
787787
) -> Union[dict, AsyncJob]:
788-
# TODO: make private in favor of Dataset.append invocation
789788
if not self.is_scene:
790789
raise Exception(
791790
"Your dataset is not a scene dataset but only supports single dataset items. "
@@ -795,6 +794,7 @@ def _append_video_scenes(
795794
)
796795

797796
for scene in scenes:
797+
scene.use_privacy_mode = self.use_privacy_mode
798798
scene.validate()
799799

800800
if not asynchronous:

nucleus/scene.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
POINTCLOUD_LOCATION_KEY,
1515
REFERENCE_ID_KEY,
1616
TRACKS_KEY,
17+
UPLOAD_TO_SCALE_KEY,
1718
VIDEO_LOCATION_KEY,
1819
VIDEO_URL_KEY,
1920
)
@@ -507,6 +508,7 @@ class VideoScene(ABC):
507508
metadata: Optional[dict] = field(default_factory=dict)
508509
attachment_type: Optional[str] = None
509510
tracks: List[Track] = field(default_factory=list)
511+
use_privacy_mode: bool = False
510512

511513
def __post_init__(self):
512514
if self.attachment_type:
@@ -534,7 +536,6 @@ def length(self) -> int:
534536
return len(self.items)
535537

536538
def validate(self):
537-
# TODO: make private
538539
assert (
539540
self.items or self.video_location
540541
), "Please upload either a video_location or an array of dataset items representing frames"
@@ -545,9 +546,10 @@ def validate(self):
545546
assert (
546547
self.length > 0
547548
), "When uploading an array of items scene must have a list of items of length at least 1"
548-
assert (
549-
not self.video_location
550-
), "No video location is accepted when uploading an array of items unless you are using privacy mode"
549+
if not self.use_privacy_mode:
550+
assert (
551+
not self.video_location
552+
), "No video location is accepted when uploading an array of items unless you are using privacy mode"
551553
for item in self.items:
552554
assert isinstance(
553555
item, DatasetItem
@@ -577,9 +579,10 @@ def add_item(
577579
update: Whether to overwrite the item at the specified index, if it
578580
exists. Default is False.
579581
"""
580-
assert (
581-
not self.video_location
582-
), "Cannot add item to a video without items"
582+
if not self.use_privacy_mode:
583+
assert (
584+
not self.video_location
585+
), "Cannot add item to a video without items"
583586
if index is None:
584587
index = len(self.items)
585588
assert (
@@ -598,9 +601,10 @@ def get_item(self, index: int) -> DatasetItem:
598601
599602
Return:
600603
:class:`DatasetItem`: DatasetItem at the specified index."""
601-
assert (
602-
not self.video_location
603-
), "Cannot add item to a video without items"
604+
if not self.use_privacy_mode:
605+
assert (
606+
not self.video_location
607+
), "Cannot add item to a video without items"
604608
if index < 0 or index > len(self.items):
605609
raise ValueError(
606610
f"This scene does not have an item at index {index}"
@@ -613,9 +617,10 @@ def get_items(self) -> List[DatasetItem]:
613617
Returns:
614618
List[:class:`DatasetItem`]: List of DatasetItems, sorted by index ascending.
615619
"""
616-
assert (
617-
not self.video_location
618-
), "Cannot add item to a video without items"
620+
if not self.use_privacy_mode:
621+
assert (
622+
not self.video_location
623+
), "Cannot add item to a video without items"
619624
return self.items
620625

621626
def info(self):
@@ -679,6 +684,9 @@ def to_payload(self) -> dict:
679684
payload[METADATA_KEY] = self.metadata
680685
if self.video_location:
681686
payload[VIDEO_URL_KEY] = self.video_location
687+
# needed in order for the backed validation to work
688+
if self.use_privacy_mode is not None:
689+
payload[UPLOAD_TO_SCALE_KEY] = not self.use_privacy_mode
682690
if self.items:
683691
items_payload = [
684692
item.to_payload(is_scene=True) for item in self.items

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ ignore = ["E501", "E741", "E731", "F401"] # Easy ignore for getting it running
2525

2626
[tool.poetry]
2727
name = "scale-nucleus"
28-
version = "0.16.8"
28+
version = "0.16.9"
2929
description = "The official Python client library for Nucleus, the Data Platform for AI"
3030
license = "MIT"
3131
authors = ["Scale AI Nucleus Team <nucleusapi@scaleapi.com>"]

tests/test_video_scene.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
REFERENCE_ID_KEY,
1313
SCENES_KEY,
1414
TYPE_KEY,
15+
UPLOAD_TO_SCALE_KEY,
1516
URL_KEY,
1617
VIDEO_URL_KEY,
1718
)
@@ -106,6 +107,7 @@ def test_video_scene_add_item():
106107
assert scene.to_payload() == {
107108
REFERENCE_ID_KEY: scene_ref_id,
108109
FRAME_RATE_KEY: frame_rate,
110+
UPLOAD_TO_SCALE_KEY: True,
109111
FRAMES_KEY: [
110112
{
111113
URL_KEY: TEST_VIDEO_ITEMS[2].image_location,

0 commit comments

Comments
 (0)