Skip to content

Commit 25144b7

Browse files
author
Matt Sokoloff
committed
wip
1 parent 9d37d5a commit 25144b7

File tree

5 files changed

+87
-23
lines changed

5 files changed

+87
-23
lines changed

labelbox/schema/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import labelbox.schema.asset_metadata
2+
import labelbox.schema.asset_attachment
23
import labelbox.schema.bulk_import_request
34
import labelbox.schema.benchmark
45
import labelbox.schema.data_row

labelbox/schema/asset_attachment.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from enum import Enum
2+
from labelbox.orm.db_object import DbObject
3+
from labelbox.orm.model import Field
4+
5+
class AssetAttachment(DbObject):
6+
""" Asset attachment provides extra context about an asset while labeling.
7+
8+
Attributes:
9+
attachment_type (str): IMAGE, VIDEO, TEXT, or IMAGE_OVERLAY
10+
attachment_value (str): URL to an external file or a string of text
11+
"""
12+
13+
class MetaType(Enum):
14+
VIDEO = "VIDEO"
15+
IMAGE = "IMAGE"
16+
TEXT = "TEXT"
17+
IMAGE_OVERLAY = "IMAGE_OVERLAY"
18+
19+
# For backwards compatibility
20+
for topic in MetaType:
21+
vars()[topic.name] = topic.value
22+
23+
24+
attachment_type = Field.String("attachment_type")
25+
attachment_value = Field.String("attachment_value")

labelbox/schema/asset_metadata.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
from enum import Enum
2+
import logging
23

34
from labelbox.orm.db_object import DbObject
45
from labelbox.orm.model import Field
56

7+
logger = logging.getLogger(__name__)
68

79
class AssetMetadata(DbObject):
810
""" Asset metadata (AKA Attachments) provides extra context about an asset while labeling.
@@ -12,6 +14,12 @@ class AssetMetadata(DbObject):
1214
meta_value (str): URL to an external file or a string of text
1315
"""
1416

17+
def __init__(self, *args, **kwargs):
18+
super().__init__(*args, **kwargs)
19+
logger.warning(
20+
"`create_metadata` is deprecated. Use `create_attachment` instead."
21+
)
22+
1523
class MetaType(Enum):
1624
VIDEO = "VIDEO"
1725
IMAGE = "IMAGE"

labelbox/schema/data_row.py

Lines changed: 51 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
from labelbox.orm import query
22
from labelbox.orm.db_object import DbObject, Updateable, BulkDeletable
33
from labelbox.orm.model import Entity, Field, Relationship
4-
from labelbox.schema.asset_metadata import AssetMetadata
4+
from labelbox.schema.asset_attchment import AssetAttachment
55

6+
import logging
7+
8+
logger = logging.getLogger(__name__)
69

710
class DataRow(DbObject, Updateable, BulkDeletable):
811
""" Internal Labelbox representation of a single piece of data (e.g. image, video, text).
@@ -33,12 +36,15 @@ class DataRow(DbObject, Updateable, BulkDeletable):
3336
created_by = Relationship.ToOne("User", False, "created_by")
3437
organization = Relationship.ToOne("Organization", False)
3538
labels = Relationship.ToMany("Label", True)
39+
3640
metadata = Relationship.ToMany("AssetMetadata", False, "metadata")
41+
# attachments
42+
attachment = Relationship.ToMany("AssetAttachment", False, "attachment")
3743

3844
predictions = Relationship.ToMany("Prediction", False)
3945

40-
supported_meta_types = {
41-
meta_type.value for meta_type in AssetMetadata.MetaType
46+
supported_meta_types = supported_attachment_types = {
47+
attachment_type.value for attachment_type in AssetAttachment.MetaType
4248
}
4349

4450
@staticmethod
@@ -54,42 +60,66 @@ def __init__(self, *args, **kwargs):
5460
super().__init__(*args, **kwargs)
5561
self.metadata.supports_filtering = False
5662
self.metadata.supports_sorting = False
63+
self.attachment.supports_filtering = False
64+
self.attachment.supports_sorting = False
5765

58-
def create_metadata(self, meta_type, meta_value):
66+
def create_attachment(self, attachment_type, attachment_value):
5967
""" Attaches asset metadata to a DataRow.
6068
61-
>>> datarow.create_metadata("TEXT", "This is a text message")
69+
>>> datarow.create_attachment("TEXT", "This is a text message")
6270
6371
Args:
64-
meta_type (str): Asset metadata type, must be one of:
65-
VIDEO, IMAGE, TEXT, IMAGE_OVERLAY (AssetMetadata.MetaType)
66-
meta_value (str): Asset metadata value.
72+
meta_type (str): Asset attachment type, must be one of:
73+
VIDEO, IMAGE, TEXT, IMAGE_OVERLAY (AssetAttachment.AttachmentType)
74+
meta_value (str): Asset attachment value.
6775
Returns:
68-
`AssetMetadata` DB object.
76+
`AssetAttachment` DB object.
6977
Raises:
70-
ValueError: meta_type must be one of the supported types.
78+
ValueError: asset_type must be one of the supported types.
7179
"""
7280

73-
if meta_type not in self.supported_meta_types:
81+
if attachment_type not in self.supported_attachment_types:
7482
raise ValueError(
75-
f"meta_type must be one of {self.supported_meta_types}. Found {meta_type}"
83+
f"meta_type must be one of {self.supported_attachment_types}. Found {attachment_type}"
7684
)
7785

78-
meta_type_param = "metaType"
79-
meta_value_param = "metaValue"
86+
attachment_type_param = "type"
87+
attachment_value_param = "value"
8088
data_row_id_param = "dataRowId"
81-
query_str = """mutation CreateAssetMetadataPyApi(
89+
query_str = """mutation CreateDataRowAttachmentPyApi(
8290
$%s: AttachmentType!, $%s: String!, $%s: ID!) {
83-
createAssetMetadata(data: {
84-
metaType: $%s metaValue: $%s dataRowId: $%s}) {%s}} """ % (
85-
meta_type_param, meta_value_param, data_row_id_param,
86-
meta_type_param, meta_value_param, data_row_id_param,
91+
createDataRowAttachment(data: {
92+
type: $%s value: $%s dataRowId: $%s}) {%s}} """ % (
93+
attachment_type_param, attachment_value_param, data_row_id_param,
94+
attachment_type_param, attachment_value_param, data_row_id_param,
8795
query.results_query_part(Entity.AssetMetadata))
8896

8997
res = self.client.execute(
9098
query_str, {
91-
meta_type_param: meta_type,
92-
meta_value_param: meta_value,
99+
attachment_type_param: meta_type,
100+
attachment_value_param: meta_value,
93101
data_row_id_param: self.uid
94102
})
103+
return Entity.AssetAttachment(self.client, res["createAssetMetadata"])
104+
105+
106+
createDataRowAttachment(data: DataRowAttachmentCreateInput!): DataRowAttachment!
107+
deleteDataRowAttachment(where: WhereUniqueIdInput!): DataRowAttachment!
108+
updateDataRowAttachment
109+
110+
111+
112+
def create_metadata(self, meta_type, meta_value):
113+
"""
114+
115+
This function is deprecated. Use create_attachment instead
116+
117+
Returns:
118+
AssetMetadata
119+
"""
120+
logger.warning(
121+
"`create_metadata` is deprecated. Use `create_attachment` instead."
122+
)
123+
124+
attachment = self.create_attachment(meta_type, meta_value)
95125
return Entity.AssetMetadata(self.client, res["createAssetMetadata"])

labelbox/schema/organization.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ def invite_limit(self) -> InviteLimit:
103103
""" Retrieve invite limits for the org
104104
This already accounts for users currently in the org
105105
Meaining that `used = users + invites, remaining = limit - (users + invites)`
106-
106+
107107
Returns:
108108
InviteLimit
109-
109+
110110
"""
111111
org_id_param = "organizationId"
112112
res = self.client.execute("""query InvitesLimitPyApi($%s: ID!) {

0 commit comments

Comments
 (0)