Skip to content

Commit 9aacf67

Browse files
committed
Fixed bug with model metadata write and added functionality to upload model card image
1 parent d77bc42 commit 9aacf67

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

modzy/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55

66
from .client import ApiClient # noqa
77
from .edge.client import EdgeClient
8-
__version__ = '0.10.3'
8+
__version__ = '0.10.4'
99

1010
logging.getLogger(__name__).addHandler(logging.NullHandler())

modzy/models.py

+24-3
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def update_processing_engines(
154154
return
155155
model_details = self.get_model_processing_details(model_id, version)
156156
if model_details is not None: # This means the model with the id and version is now visible
157-
engines_ready = sum([engine["ready"] for engine in model_details["engines"]])
157+
engines_ready = model_details['ready']
158158
if engines_ready >= min_engines:
159159
self.logger.info(f"{engines_ready} engines are ready.")
160160
return
@@ -440,7 +440,7 @@ def deploy(
440440
self, container_image, model_name, model_version, sample_input_file=None, architecture="amd64", credentials=None,
441441
model_id=None, run_timeout=None, status_timeout=None, short_description=None, tags=[],
442442
gpu=False, long_description=None, technical_details=None, performance_summary=None,
443-
performance_metrics=None, input_details=None, output_details=None
443+
performance_metrics=None, input_details=None, output_details=None, model_picture=None
444444
):
445445
"""Deploys a new `Model` instance.
446446
@@ -463,6 +463,7 @@ def deploy(
463463
performance_metrics (List): List of arrays describing model performance statistics
464464
input_details (List): List of dictionaries describing details of model inputs
465465
output_details (List): List of dictionaries describing details of model outputs
466+
model_picture (str): Filepath to image for model card page
466467
467468
Returns:
468469
dict: Newly deployed model information including formatted URL to newly deployed model page.
@@ -507,7 +508,7 @@ def deploy(
507508

508509
# add model metadata
509510
run_timeout_body = int(run_timeout)*1000 if run_timeout else 60000
510-
status_timeout_body = int(status_timeout)*1000 if status_timeout else 60000
511+
status_timeout_body = int(status_timeout)*1000 if status_timeout else 60000
511512

512513
if architecture in ["arm64", "arm"]:
513514
# assign "ARM" hardware requirement to bypass validation tests
@@ -539,6 +540,12 @@ def deploy(
539540
model_data = self._api_client.http.patch(f"{self._base_route}/{identifier}/versions/{version}", model_metadata_patch)
540541
self.logger.info(f"Patched Model Data: {json.dumps(model_data)}")
541542

543+
# upload model picture
544+
if model_picture:
545+
files = {'file': open(model_picture, 'rb')}
546+
params = {'description': "model card image"}
547+
res = self._api_client.http.post(f"/models/{identifier}/image", params=params, file_data=files)
548+
542549
# deploy model and skip tests (because model is compiled for arm64)
543550
try:
544551
deploy_model(self._api_client, self.logger, identifier, version)
@@ -580,6 +587,20 @@ def deploy(
580587
run_model(self._api_client, self.logger, identifier, version)
581588
except Exception as e:
582589
raise ValueError("Inference test failed. Make sure the provided input sample is valid and your model can process it for inference. \n\nSee full error below:\n{}".format(e))
590+
# make sure model metadata reflects user-specified fields
591+
try:
592+
model_data = self._api_client.http.patch(f"{self._base_route}/{identifier}/versions/{version}", model_metadata)
593+
self.logger.info(f"Model Data: {json.dumps(model_data)}")
594+
except Exception as e:
595+
raise ValueError("Patching model metadata failed. See full error below:\n\n{}".format(e))
596+
# upload model picture
597+
try:
598+
if model_picture:
599+
files = {'file': open(model_picture, 'rb')}
600+
params = {'description': "model card image"}
601+
res = self._api_client.http.post(f"/models/{identifier}/image", params=params, file_data=files)
602+
except Exception as e:
603+
self.logger("Uploading model image card failed. Continuing deployment")
583604
# deploy model pending all tests have passed
584605
try:
585606
deploy_model(self._api_client, self.logger, identifier, version)

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@
4040
# removed in 0.7.1 test_suite='tests',
4141
# removed in 0.7.1 tests_require=test_requirements,
4242
url='https://github.com/modzy/sdk-python',
43-
version='0.10.3',
43+
version='0.10.4',
4444
zip_safe=False,
4545
)

0 commit comments

Comments
 (0)