Skip to content

Commit 82b5038

Browse files
committed
ODSC-38627: adding class doc and resolve comments
1 parent 805111f commit 82b5038

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

docs/source/ads.model.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,14 @@ ads.model.extractor.pytorch\_extractor module
116116
:undoc-members:
117117
:show-inheritance:
118118

119+
ads.model.extractor.huggingface\_extractor module
120+
---------------------------------------------
121+
122+
.. automodule:: ads.model.extractor.huggingface_extractor
123+
:members:
124+
:undoc-members:
125+
:show-inheritance:
126+
119127
Module contents
120128
---------------
121129

docs/source/ads.model_framework.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ ads.model.framework.xgboost\_model module
5252
:undoc-members:
5353
:show-inheritance:
5454

55+
ads.model.framework.huggingface\_model module
56+
-----------------------------------------
57+
58+
.. automodule:: ads.model.framework.huggingface_model
59+
:members:
60+
:undoc-members:
61+
:show-inheritance:
62+
5563
Module contents
5664
---------------
5765

docs/source/user_guide/model_registration/frameworks/huggingfacemodel.rst

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)