orient_express 0.3.2__tar.gz → 0.3.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {orient_express-0.3.2 → orient_express-0.3.3}/PKG-INFO +1 -1
- {orient_express-0.3.2 → orient_express-0.3.3}/orient_express/model_wrapper.py +18 -5
- {orient_express-0.3.2 → orient_express-0.3.3}/pyproject.toml +1 -1
- {orient_express-0.3.2 → orient_express-0.3.3}/README.md +0 -0
- {orient_express-0.3.2 → orient_express-0.3.3}/orient_express/__init__.py +0 -0
|
@@ -44,15 +44,22 @@ class ModelExpress:
|
|
|
44
44
|
else:
|
|
45
45
|
self.endpoint_name = endpoint_name
|
|
46
46
|
|
|
47
|
+
self._vertex_initialized = False
|
|
48
|
+
|
|
47
49
|
def colab_auth(self):
|
|
48
50
|
from google.colab import auth
|
|
49
51
|
|
|
50
52
|
auth.authenticate_user()
|
|
51
53
|
|
|
52
54
|
def _vertex_init(self):
|
|
53
|
-
|
|
55
|
+
if not self._vertex_initialized:
|
|
56
|
+
aiplatform.init(project=self.project_name, location=self.region)
|
|
57
|
+
self._vertex_initialized = True
|
|
54
58
|
|
|
55
59
|
def get_latest_vertex_model(self, model_name):
|
|
60
|
+
"""If there are a few models with the same name, load the most recent one.
|
|
61
|
+
It's highly recommended to keep only 1 model with the same name to avoid the confusion
|
|
62
|
+
"""
|
|
56
63
|
self._vertex_init()
|
|
57
64
|
|
|
58
65
|
# Search for models with the specified display name
|
|
@@ -153,6 +160,8 @@ class ModelExpress:
|
|
|
153
160
|
)
|
|
154
161
|
|
|
155
162
|
def remote_predict(self, input_df):
|
|
163
|
+
self._vertex_init()
|
|
164
|
+
|
|
156
165
|
if not self.endpoint:
|
|
157
166
|
endpoint = self.get_endpoint()
|
|
158
167
|
if not endpoint:
|
|
@@ -166,6 +175,8 @@ class ModelExpress:
|
|
|
166
175
|
return predictions.predictions
|
|
167
176
|
|
|
168
177
|
def local_predict(self, input_df):
|
|
178
|
+
self._vertex_init()
|
|
179
|
+
|
|
169
180
|
if not self.model:
|
|
170
181
|
self.load_model_from_registry()
|
|
171
182
|
|
|
@@ -178,14 +189,16 @@ class ModelExpress:
|
|
|
178
189
|
return self.model.predict_proba(input_df)
|
|
179
190
|
|
|
180
191
|
def load_model_from_registry(self):
|
|
192
|
+
self._vertex_init()
|
|
193
|
+
|
|
194
|
+
vertex_model = self.get_latest_vertex_model(self.model_name)
|
|
195
|
+
|
|
181
196
|
if self.model_version:
|
|
197
|
+
# reload the model using a specific model version
|
|
182
198
|
vertex_model = aiplatform.Model(
|
|
183
|
-
model_name=
|
|
199
|
+
model_name=vertex_model.resource_name, version=str(self.model_version)
|
|
184
200
|
)
|
|
185
201
|
|
|
186
|
-
else:
|
|
187
|
-
vertex_model = self.get_latest_vertex_model(self.model_name)
|
|
188
|
-
|
|
189
202
|
if not vertex_model:
|
|
190
203
|
raise Exception(f"Model '{self.model_name}' not found in the registry.")
|
|
191
204
|
|
|
File without changes
|
|
File without changes
|