Skip to content

Commit 423b2db

Browse files
Josselin BUILSjosselinbuils
authored andcommitted
feat(LAB-3395): manage asset level video transcriptions in kili export
1 parent d7fefe2 commit 423b2db

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/kili/adapters/kili_api_gateway/label/annotation_to_json_response.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
)
2121
from kili.domain.ontology import JobName, JobTool
2222

23+
ASSET_LEVEL_KEY = "assetLevel"
24+
2325

2426
class AnnotationsToJsonResponseConverter:
2527
"""Convert annotations to JSON response."""
@@ -81,7 +83,9 @@ def _add_annotation_metadata(annotations: List[VideoAnnotation], json_response:
8183

8284

8385
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+
)
8589
for frame_id in range(max_frame_id + 1):
8690
json_response.setdefault(str(frame_id), {})
8791

@@ -98,7 +102,12 @@ def _video_annotations_to_json_response(
98102

99103
other_annotations = annotations[:i] + annotations[i + 1 :]
100104

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":
102111
ann = cast(VideoObjectDetectionAnnotation, ann)
103112
ann_json_resp = _video_object_detection_annotation_to_json_response(
104113
ann, other_annotations, json_interface=json_interface
@@ -133,7 +142,11 @@ def _video_annotations_to_json_response(
133142
_add_annotation_metadata(annotations, json_resp)
134143
_fill_empty_frames(json_resp)
135144

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
137150

138151

139152
def _classic_annotations_to_json_response(

0 commit comments

Comments
 (0)