@@ -19,11 +19,12 @@ class NDAnswer(ConfidenceMixin, CustomMetricsMixin):
19
19
name : Optional [str ] = None
20
20
schema_id : Optional [Cuid ] = None
21
21
classifications : Optional [List ['NDSubclassificationType' ]] = None
22
- model_config = ConfigDict (populate_by_name = True , alias_generator = to_camel )
22
+ model_config = ConfigDict (populate_by_name = True , alias_generator = to_camel )
23
23
24
24
@model_validator (mode = "after" )
25
25
def must_set_one (self ):
26
- if (not hasattr (self , "schema_id" ) or self .schema_id is None ) and (not hasattr (self , "name" ) or self .name is None ):
26
+ if (not hasattr (self , "schema_id" ) or self .schema_id
27
+ is None ) and (not hasattr (self , "name" ) or self .name is None ):
27
28
raise ValueError ("Schema id or name are not set. Set either one." )
28
29
return self
29
30
@@ -103,7 +104,10 @@ def from_common(cls, checklist: Checklist, name: str,
103
104
NDAnswer (name = answer .name ,
104
105
schema_id = answer .feature_schema_id ,
105
106
confidence = answer .confidence ,
106
- classifications = [NDSubclassification .from_common (annot ) for annot in answer .classifications ] if answer .classifications else None ,
107
+ classifications = [
108
+ NDSubclassification .from_common (annot )
109
+ for annot in answer .classifications
110
+ ] if answer .classifications else None ,
107
111
custom_metrics = answer .custom_metrics )
108
112
for answer in checklist .answer
109
113
],
@@ -153,8 +157,8 @@ class NDPromptTextSubclass(NDAnswer):
153
157
154
158
def to_common (self ) -> PromptText :
155
159
return PromptText (answer = self .answer ,
156
- confidence = self .confidence ,
157
- custom_metrics = self .custom_metrics )
160
+ confidence = self .confidence ,
161
+ custom_metrics = self .custom_metrics )
158
162
159
163
@classmethod
160
164
def from_common (cls , prompt_text : PromptText , name : str ,
@@ -195,7 +199,8 @@ def from_common(cls,
195
199
)
196
200
197
201
198
- class NDChecklist (NDAnnotation , NDChecklistSubclass , VideoSupported , _SubclassRegistryBase ):
202
+ class NDChecklist (NDAnnotation , NDChecklistSubclass , VideoSupported ,
203
+ _SubclassRegistryBase ):
199
204
200
205
@model_serializer (mode = "wrap" )
201
206
def serialize_model (self , handler ):
@@ -238,7 +243,8 @@ def from_common(
238
243
confidence = confidence )
239
244
240
245
241
- class NDRadio (NDAnnotation , NDRadioSubclass , VideoSupported , _SubclassRegistryBase ):
246
+ class NDRadio (NDAnnotation , NDRadioSubclass , VideoSupported ,
247
+ _SubclassRegistryBase ):
242
248
243
249
@classmethod
244
250
def from_common (
@@ -267,35 +273,32 @@ def from_common(
267
273
frames = extra .get ('frames' ),
268
274
message_id = message_id ,
269
275
confidence = confidence )
270
-
276
+
271
277
@model_serializer (mode = "wrap" )
272
278
def serialize_model (self , handler ):
273
279
res = handler (self )
274
280
if "classifications" in res and res ["classifications" ] == []:
275
281
del res ["classifications" ]
276
282
return res
277
-
278
-
283
+
284
+
279
285
class NDPromptText (NDAnnotation , NDPromptTextSubclass , _SubclassRegistryBase ):
280
-
286
+
281
287
@classmethod
282
- def from_common (
283
- cls ,
284
- uuid : str ,
285
- text : PromptText ,
286
- name ,
287
- data : Dict ,
288
- feature_schema_id : Cuid ,
289
- confidence : Optional [float ] = None
290
- ) -> "NDPromptText" :
291
- return cls (
292
- answer = text .answer ,
293
- data_row = DataRow (id = data .uid , global_key = data .global_key ),
294
- name = name ,
295
- schema_id = feature_schema_id ,
296
- uuid = uuid ,
297
- confidence = text .confidence ,
298
- custom_metrics = text .custom_metrics )
288
+ def from_common (cls ,
289
+ uuid : str ,
290
+ text : PromptText ,
291
+ name ,
292
+ data : Dict ,
293
+ feature_schema_id : Cuid ,
294
+ confidence : Optional [float ] = None ) -> "NDPromptText" :
295
+ return cls (answer = text .answer ,
296
+ data_row = DataRow (id = data .uid , global_key = data .global_key ),
297
+ name = name ,
298
+ schema_id = feature_schema_id ,
299
+ uuid = uuid ,
300
+ confidence = text .confidence ,
301
+ custom_metrics = text .custom_metrics )
299
302
300
303
301
304
class NDSubclassification :
@@ -351,7 +354,8 @@ def to_common(
351
354
for frame in annotation .frames :
352
355
for idx in range (frame .start , frame .end + 1 , 1 ):
353
356
results .append (
354
- VideoClassificationAnnotation (frame = idx , ** common .model_dump (exclude_none = True )))
357
+ VideoClassificationAnnotation (
358
+ frame = idx , ** common .model_dump (exclude_none = True )))
355
359
return results
356
360
357
361
@classmethod
@@ -383,6 +387,7 @@ def lookup_classification(
383
387
Radio : NDRadio
384
388
}.get (type (annotation .value ))
385
389
390
+
386
391
class NDPromptClassification :
387
392
388
393
@staticmethod
@@ -405,8 +410,7 @@ def from_common(
405
410
data : Union [VideoData , TextData , ImageData ]
406
411
) -> Union [NDTextSubclass , NDChecklistSubclass , NDRadioSubclass ]:
407
412
return NDPromptText .from_common (str (annotation ._uuid ), annotation .value ,
408
- annotation .name ,
409
- data ,
413
+ annotation .name , data ,
410
414
annotation .feature_schema_id ,
411
415
annotation .confidence )
412
416
@@ -428,4 +432,4 @@ def from_common(
428
432
# Make sure to keep NDChecklist prior to NDRadio in the list,
429
433
# otherwise list of answers gets parsed by NDRadio whereas NDChecklist must be used
430
434
NDClassificationType = Union [NDChecklist , NDRadio , NDText ]
431
- NDPromptClassificationType = Union [NDPromptText ]
435
+ NDPromptClassificationType = Union [NDPromptText ]
0 commit comments