20
20
)
21
21
from kili .domain .ontology import JobName , JobTool
22
22
23
+ ASSET_LEVEL_KEY = "assetLevel"
24
+
23
25
24
26
class AnnotationsToJsonResponseConverter :
25
27
"""Convert annotations to JSON response."""
@@ -81,7 +83,9 @@ def _add_annotation_metadata(annotations: List[VideoAnnotation], json_response:
81
83
82
84
83
85
def _fill_empty_frames (json_response : Dict ) -> None :
84
- max_frame_id = max ((int (frame_id ) for frame_id in json_response ), default = - 1 )
86
+ max_frame_id = max (
87
+ (int (frame_id ) for frame_id in json_response if frame_id != ASSET_LEVEL_KEY ), default = - 1
88
+ )
85
89
for frame_id in range (max_frame_id + 1 ):
86
90
json_response .setdefault (str (frame_id ), {})
87
91
@@ -98,7 +102,12 @@ def _video_annotations_to_json_response(
98
102
99
103
other_annotations = annotations [:i ] + annotations [i + 1 :]
100
104
101
- if ann ["__typename" ] == "VideoObjectDetectionAnnotation" :
105
+ if ann ["__typename" ] == "TranscriptionAnnotation" :
106
+ ann = cast (TranscriptionAnnotation , ann )
107
+ ann_json_resp = _transcription_annotation_to_json_response (ann )
108
+ json_resp [ASSET_LEVEL_KEY ] = {** json_resp [ASSET_LEVEL_KEY ], ** ann_json_resp }
109
+
110
+ elif ann ["__typename" ] == "VideoObjectDetectionAnnotation" :
102
111
ann = cast (VideoObjectDetectionAnnotation , ann )
103
112
ann_json_resp = _video_object_detection_annotation_to_json_response (
104
113
ann , other_annotations , json_interface = json_interface
@@ -133,7 +142,11 @@ def _video_annotations_to_json_response(
133
142
_add_annotation_metadata (annotations , json_resp )
134
143
_fill_empty_frames (json_resp )
135
144
136
- return dict (sorted (json_resp .items (), key = lambda item : int (item [0 ]))) # sort by frame id
145
+ return dict (
146
+ sorted (
147
+ json_resp .items (), key = lambda item : - 1 if item [0 ] == ASSET_LEVEL_KEY else int (item [0 ])
148
+ )
149
+ ) # sort by frame id
137
150
138
151
139
152
def _classic_annotations_to_json_response (
0 commit comments