updates with cls
Browse files- handler.py +9 -3
handler.py
CHANGED
@@ -7,10 +7,9 @@ class EndpointHandler:
|
|
7 |
_instance = None # Singleton instance
|
8 |
_model_loaded = False # Flag to check if the model is loaded
|
9 |
|
10 |
-
def __new__(cls, *args, **kwargs):
|
11 |
if not cls._instance:
|
12 |
-
cls._instance = super(EndpointHandler, cls).__new__(cls
|
13 |
-
cls._instance._model_loaded = False
|
14 |
return cls._instance
|
15 |
|
16 |
def __init__(self, model_path=""):
|
@@ -40,6 +39,13 @@ class EndpointHandler:
|
|
40 |
}
|
41 |
|
42 |
self._model_loaded = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
def __call__(self, data: Union[Dict[str, Any], str]) -> List[Dict[str, Any]]:
|
45 |
"""
|
|
|
7 |
_instance = None # Singleton instance
|
8 |
_model_loaded = False # Flag to check if the model is loaded
|
9 |
|
10 |
+
def __new__(cls, *args, **kwargs): # Allow arguments to pass through
|
11 |
if not cls._instance:
|
12 |
+
cls._instance = super(EndpointHandler, cls).__new__(cls)
|
|
|
13 |
return cls._instance
|
14 |
|
15 |
def __init__(self, model_path=""):
|
|
|
39 |
}
|
40 |
|
41 |
self._model_loaded = True
|
42 |
+
|
43 |
+
@classmethod
|
44 |
+
def get_instance(cls, model_path=""):
|
45 |
+
"""Provides access to the singleton instance."""
|
46 |
+
if not cls._instance:
|
47 |
+
cls._instance = cls(model_path) # Create instance if it doesn't exist
|
48 |
+
return cls._instance
|
49 |
|
50 |
def __call__(self, data: Union[Dict[str, Any], str]) -> List[Dict[str, Any]]:
|
51 |
"""
|