@@ -164,12 +164,19 @@ Model deployment endpoints can be invoked with the oci sdk. This example invokes
164164
165165 >>> import requests
166166 >>> import oci
167- >>> import ads
167+ >>> from ads.common.auth import default_signer
168+ >>> import cloudpickle
169+ >>> import PIL.Image
168170 >>> import cloudpickle
169171 >>> headers = {"Content-Type": "application/octet-stream"}
170172 >>> endpoint = huggingface_pipeline_model.model_deployment.url + "/predict"
171173
172- >>> preds = requests.post(endpoint, data=image_bytes, auth=ads.common.auth.default_signer()['signer'], headers=headers).json()
174+ ## download the image
175+ image_url = "https://huggingface.co/datasets/Narsil/image_dummy/raw/main/parrots.png"
176+ image = PIL.Image.open(requests.get(image_link, stream=True).raw)
177+ image_bytes = cloudpickle.dumps(image)
178+
179+ >>> preds = requests.post(endpoint, data=image_bytes, auth=default_signer()['signer'], headers=headers).json()
173180 >>> print([{"score": round(pred["score"], 4), "label": pred["label"]} for pred in preds['prediction']])
174181 [{'score': 0.9879, 'label': 'LABEL_184'},
175182 {'score': 0.9973, 'label': 'snow'},
@@ -182,9 +189,11 @@ Example
182189.. code-block :: python3
183190
184191 from transformers import pipeline
192+ from ads.model import HuggingFacePipelineModel
193+
185194 import tempfile
186195 import PIL.Image
187- import ads
196+ from ads.common.auth import default_signer
188197 import requests
189198 import cloudpickle
190199
@@ -205,10 +214,10 @@ Example
205214
206215 # Autogenerate score.py, serialized model, runtime.yaml
207216 conda_pack_path = "oci://bucket@namespace/path/to/conda/pack"
208- python_version = "3.x"
217+ python_version = "3.x" # Remember to update 3.x with your actual python version, e.g. 3.8
209218 zero_shot_image_classification_model.prepare(inference_conda_env=conda_pack_path, inference_python_version = python_version, force_overwrite=True)
210219
211- ## Test data
220+ ## Convert payload to bytes
212221 data = {"images": image, "candidate_labels": ["animals", "humans", "landscape"]}
213222 body = cloudpickle.dumps(data) # convert image to bytes
214223
@@ -231,7 +240,7 @@ Example
231240 zero_shot_image_classification_model.predict(body)
232241
233242 ### Invoke the model by sending bytes
234- auth = ads.common.auth. default_signer()['signer']
243+ auth = default_signer()['signer']
235244 endpoint = zero_shot_image_classification_model.model_deployment.url + "/predict"
236245 headers = {"Content-Type": "application/octet-stream"}
237246 requests.post(endpoint, data=body, auth=auth, headers=headers).json()
0 commit comments