35
35
36
36
logger = logging .getLogger (__name__ )
37
37
38
+ LABEL_STUDIO_ML_BACKEND_V2_DEFAULT = False
39
+
38
40
@attr .s
39
41
class ModelWrapper (object ):
40
42
model = attr .ib ()
@@ -444,24 +446,40 @@ def _key(cls, project):
444
446
445
447
@classmethod
446
448
def has_active_model (cls , project ):
447
- return cls ._key (project ) in cls ._current_model
449
+ if not os .getenv ('LABEL_STUDIO_ML_BACKEND_V2' , default = LABEL_STUDIO_ML_BACKEND_V2_DEFAULT ):
450
+ # TODO: Deprecated branch since LS 1.5
451
+ return cls ._key (project ) in cls ._current_model
452
+ else :
453
+ return cls ._current_model is not None
448
454
449
455
@classmethod
450
456
def get (cls , project ):
451
- key = cls ._key (project )
452
- logger .debug ('Get project ' + str (key ))
453
- return cls ._current_model .get (key )
457
+ if not os .getenv ('LABEL_STUDIO_ML_BACKEND_V2' , default = LABEL_STUDIO_ML_BACKEND_V2_DEFAULT ):
458
+ # TODO: Deprecated branch since LS 1.5
459
+ key = cls ._key (project )
460
+ logger .debug ('Get project ' + str (key ))
461
+ return cls ._current_model .get (key )
462
+ else :
463
+ return cls ._current_model
454
464
455
465
@classmethod
456
466
def create (cls , project = None , label_config = None , train_output = None , version = None , ** kwargs ):
457
467
key = cls ._key (project )
458
468
logger .debug ('Create project ' + str (key ))
459
469
kwargs .update (cls .init_kwargs )
460
- cls ._current_model [key ] = ModelWrapper (
461
- model = cls .model_class (label_config = label_config , train_output = train_output , ** kwargs ),
462
- model_version = version or cls ._generate_version ()
463
- )
464
- return cls ._current_model [key ]
470
+ if not os .getenv ('LABEL_STUDIO_ML_BACKEND_V2' , default = LABEL_STUDIO_ML_BACKEND_V2_DEFAULT ):
471
+ # TODO: Deprecated branch since LS 1.5
472
+ cls ._current_model [key ] = ModelWrapper (
473
+ model = cls .model_class (label_config = label_config , train_output = train_output , ** kwargs ),
474
+ model_version = version or cls ._generate_version ()
475
+ )
476
+ return cls ._current_model [key ]
477
+ else :
478
+ cls ._current_model = ModelWrapper (
479
+ model = cls .model_class (label_config = label_config , train_output = train_output , ** kwargs ),
480
+ model_version = version or cls ._generate_version ()
481
+ )
482
+ return cls ._current_model
465
483
466
484
@classmethod
467
485
def get_or_create (
@@ -476,8 +494,8 @@ def get_or_create(
476
494
477
495
@classmethod
478
496
def fetch (cls , project = None , label_config = None , force_reload = False , ** kwargs ):
479
- if not os .getenv ('LABEL_STUDIO_ML_BACKEND_V2' , default = True ):
480
- # TODO: Deprecated branch
497
+ if not os .getenv ('LABEL_STUDIO_ML_BACKEND_V2' , default = LABEL_STUDIO_ML_BACKEND_V2_DEFAULT ):
498
+ # TODO: Deprecated branch since LS 1.5
481
499
if cls .without_redis ():
482
500
logger .debug ('Fetch ' + project + ' from local directory' )
483
501
job_result = cls ._get_latest_job_result_from_workdir (project ) or {}
@@ -554,7 +572,7 @@ def is_training(cls, project):
554
572
def predict (
555
573
cls , tasks , project = None , label_config = None , force_reload = False , try_fetch = True , ** kwargs
556
574
):
557
- if not os .getenv ('LABEL_STUDIO_ML_BACKEND_V2' , default = True ):
575
+ if not os .getenv ('LABEL_STUDIO_ML_BACKEND_V2' , default = LABEL_STUDIO_ML_BACKEND_V2_DEFAULT ):
558
576
if try_fetch :
559
577
m = cls .fetch (project , label_config , force_reload )
560
578
else :
0 commit comments