1
1
from labelbox .orm import query
2
2
from labelbox .orm .db_object import DbObject , Updateable , BulkDeletable
3
3
from labelbox .orm .model import Entity , Field , Relationship
4
- from labelbox .schema .asset_metadata import AssetMetadata
4
+ from labelbox .schema .asset_attchment import AssetAttachment
5
5
6
+ import logging
7
+
8
+ logger = logging .getLogger (__name__ )
6
9
7
10
class DataRow (DbObject , Updateable , BulkDeletable ):
8
11
""" Internal Labelbox representation of a single piece of data (e.g. image, video, text).
@@ -33,12 +36,15 @@ class DataRow(DbObject, Updateable, BulkDeletable):
33
36
created_by = Relationship .ToOne ("User" , False , "created_by" )
34
37
organization = Relationship .ToOne ("Organization" , False )
35
38
labels = Relationship .ToMany ("Label" , True )
39
+
36
40
metadata = Relationship .ToMany ("AssetMetadata" , False , "metadata" )
41
+ # attachments
42
+ attachment = Relationship .ToMany ("AssetAttachment" , False , "attachment" )
37
43
38
44
predictions = Relationship .ToMany ("Prediction" , False )
39
45
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
42
48
}
43
49
44
50
@staticmethod
@@ -54,42 +60,66 @@ def __init__(self, *args, **kwargs):
54
60
super ().__init__ (* args , ** kwargs )
55
61
self .metadata .supports_filtering = False
56
62
self .metadata .supports_sorting = False
63
+ self .attachment .supports_filtering = False
64
+ self .attachment .supports_sorting = False
57
65
58
- def create_metadata (self , meta_type , meta_value ):
66
+ def create_attachment (self , attachment_type , attachment_value ):
59
67
""" Attaches asset metadata to a DataRow.
60
68
61
- >>> datarow.create_metadata ("TEXT", "This is a text message")
69
+ >>> datarow.create_attachment ("TEXT", "This is a text message")
62
70
63
71
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.
67
75
Returns:
68
- `AssetMetadata ` DB object.
76
+ `AssetAttachment ` DB object.
69
77
Raises:
70
- ValueError: meta_type must be one of the supported types.
78
+ ValueError: asset_type must be one of the supported types.
71
79
"""
72
80
73
- if meta_type not in self .supported_meta_types :
81
+ if attachment_type not in self .supported_attachment_types :
74
82
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 } "
76
84
)
77
85
78
- meta_type_param = "metaType "
79
- meta_value_param = "metaValue "
86
+ attachment_type_param = "type "
87
+ attachment_value_param = "value "
80
88
data_row_id_param = "dataRowId"
81
- query_str = """mutation CreateAssetMetadataPyApi (
89
+ query_str = """mutation CreateDataRowAttachmentPyApi (
82
90
$%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 ,
87
95
query .results_query_part (Entity .AssetMetadata ))
88
96
89
97
res = self .client .execute (
90
98
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 ,
93
101
data_row_id_param : self .uid
94
102
})
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 )
95
125
return Entity .AssetMetadata (self .client , res ["createAssetMetadata" ])
0 commit comments