Skip to content

Commit

Permalink
separate out region generation
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-bernstein committed Nov 26, 2024
1 parent b075aee commit 78cc60f
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/label_studio_sdk/label_interface/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,13 @@ def generate_sample_task(self, mode="upload", secure_mode=False):

return task

def _generate_sample_regions(self):
""" Generate an example of each control tag's JSON schema and validate it as a region"""
return self.create_regions({
control.name: JSF(control.to_json_schema()).generate()
for control in self.controls
})

def generate_sample_prediction(self) -> Optional[dict]:
"""Generates a sample prediction that is valid for this label config.
Expand All @@ -857,10 +864,7 @@ def generate_sample_prediction(self) -> Optional[dict]:
"""
prediction = PredictionValue(
model_version='sample model version',
result=self.create_regions({
control.name: JSF(control.to_json_schema()).generate()
for control in self.controls
})
result=self._generate_sample_regions()
)
prediction_dct = prediction.model_dump()
if self.validate_prediction(prediction_dct):
Expand Down Expand Up @@ -889,10 +893,7 @@ def generate_sample_annotation(self) -> Optional[dict]:
"""
annotation = AnnotationValue(
completed_by=-1, # annotator's user id
result=self.create_regions({
control.name: JSF(control.to_json_schema()).generate()
for control in self.controls
})
result=self._generate_sample_regions()
)
annotation_dct = annotation.model_dump()
if self.validate_annotation(annotation_dct):
Expand Down

0 comments on commit 78cc60f

Please sign in to comment.