Skip to content

Commit bdfc42b

Browse files
niklubnik
andauthored
fix: RND-101: Fix ML backend compatibility with sdk>=1 (#570)
* fix: RND-101: Fix ML backend compatibility with sdk>=1 * Fix sdk version * Install sdk from git * Fix label-studio-tools imports * Install numpy in requirements * Cast float * Add numpy reqs to easyocr and nemo * Upgrade label-studio-sdk==1.0.2 --------- Co-authored-by: nik <[email protected]>
1 parent 2075289 commit bdfc42b

File tree

11 files changed

+56
-29
lines changed

11 files changed

+56
-29
lines changed

label_studio_ml/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def _predict():
7777
else:
7878
response.update_predictions_version()
7979

80-
response = response.serialize()
80+
response = response.model_dump()
8181

8282
res = response
8383
if res is None:
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
easyocr==1.7.1
22
boto3==1.28.58
3-
opencv-python-headless==4.9.0.80
3+
opencv-python-headless==4.9.0.80
4+
numpy<2

label_studio_ml/examples/huggingface_ner/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def predict(self, tasks: List[Dict], context: Optional[Dict] = None, **kwargs) -
8383
entities = list(group)
8484
start = entities[0]['start']
8585
end = entities[-1]['end']
86-
score = sum([entity['score'] for entity in entities]) / len(entities)
86+
score = float(sum([entity['score'] for entity in entities]) / len(entities))
8787
results.append({
8888
'from_name': from_name,
8989
'to_name': to_name,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
boto3>=1.26.103,<2.0.0
22
openmim~=0.3.9
3+
numpy~=1.26
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
nemo-toolkit[all]
2+
numpy<2
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
gunicorn==22.0.0
22
spacy~=3.6
33
label-studio-ml @ git+https://github.com/HumanSignal/label-studio-ml-backend.git@master
4+
numpy~=1.26

label_studio_ml/model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
from colorama import Fore
2525

2626
from label_studio_sdk.label_interface import LabelInterface
27-
from label_studio_tools.core.label_config import parse_config
28-
from label_studio_tools.core.utils.io import get_local_path
27+
from label_studio_sdk._extensions.label_studio_tools.core.label_config import parse_config
28+
from label_studio_sdk._extensions.label_studio_tools.core.utils.io import get_local_path
2929
from .response import ModelResponse
3030
from .utils import is_preload_needed
3131
from .cache import create_cache

label_studio_ml/response.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11

22
from typing import Type, Dict, Optional, List, Tuple, Any, Union
3-
from pydantic import BaseModel, confloat
3+
from pydantic import BaseModel, confloat, Field
4+
from label_studio_sdk.label_interface.objects import PredictionValue
5+
from typing import Union, List
46

5-
from label_studio_sdk.objects import PredictionValue
7+
8+
# one or multiple predictions per task
9+
SingleTaskPredictions = Union[List[PredictionValue], PredictionValue]
610

711

812
class ModelResponse(BaseModel):
913
"""
1014
"""
1115
model_version: Optional[str] = None
12-
predictions: List[PredictionValue]
16+
predictions: List[SingleTaskPredictions]
1317

1418
def has_model_version(self) -> bool:
1519
return bool(self.model_version)
@@ -18,21 +22,16 @@ def update_predictions_version(self) -> None:
1822
"""
1923
"""
2024
for prediction in self.predictions:
21-
if not prediction.model_version:
22-
prediction.model_version = self.model_version
25+
if isinstance(prediction, PredictionValue):
26+
prediction = [prediction]
27+
for p in prediction:
28+
if not p.model_version:
29+
p.model_version = self.model_version
2330

2431
def set_version(self, version: str) -> None:
2532
"""
2633
"""
2734
self.model_version = version
2835
# Set the version for each prediction
2936
self.update_predictions_version()
30-
31-
def serialize(self):
32-
"""
33-
"""
34-
return {
35-
"model_version": self.model_version,
36-
"predictions": [ p.serialize() for p in self.predictions ]
37-
}
3837

label_studio_ml/utils.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
from typing import List
99
from urllib.parse import urlparse
1010

11-
from label_studio_tools.core.utils.params import get_env
12-
from label_studio_tools.core.utils.io import get_local_path
13-
from label_studio_sdk.label_interface import LabelInterface
11+
from label_studio_sdk._extensions.label_studio_tools.core.utils.params import get_env
12+
from label_studio_sdk._extensions.label_studio_tools.core.utils.io import get_local_path
1413

1514
DATA_UNDEFINED_NAME = '$undefined$'
1615

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ colorama~=0.4
33
requests~=2.31
44
semver~=3.0.2
55
pillow~=10.3
6-
label_studio_tools @ git+https://github.com/HumanSignal/label-studio-tools.git@master
7-
label-studio-sdk==0.0.34
6+
label-studio-sdk==1.0.2
7+
# label-studio-sdk @ git+https://github.com/HumanSignal/label-studio-sdk.git

0 commit comments

Comments
 (0)