Skip to content

Commit a85852f

Browse files
authored
Merge pull request #34 from oracle/model-artifact
templates updated
2 parents 03c642b + 75d67d3 commit a85852f

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed
Binary file not shown.
Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
1+
# This is template runtime.yaml. It has default conda environment value. You can replace these values.
12
MODEL_ARTIFACT_VERSION: '3.0'
23
MODEL_DEPLOYMENT:
34
INFERENCE_CONDA_ENV:
4-
INFERENCE_ENV_PATH: <INSERT_INFERENCE_ENV_PATH>
5-
INFERENCE_ENV_SLUG: <INSERT_INFERENCE_ENV_SLUG>
6-
INFERENCE_ENV_TYPE: <INSERT_INFERENCE_ENV_TYPE>
7-
INFERENCE_PYTHON_VERSION: <INSERT_INFERENCE_PYTHON_VERSION>
5+
# Replace with the object storage path of the conda environment you want to use.
6+
# Go to https://docs.oracle.com/en-us/iaas/data-science/using/conda_environ_list.htm for a list of data_science conda environments you can use out-of-the-box
7+
INFERENCE_ENV_PATH: oci://service-conda-packs@id19sfcrra6z/service_pack/cpu/Data Exploration and Manipulation for CPU Python 3.7/2.0/dataexpl_p37_cpu_v2
8+
9+
# Replace with the slug of the environment you want to use.
10+
# Slugs for data_science environment can be found for each environment either in the notebook session Environment Explorer or here:
11+
# https://docs.oracle.com/en-us/iaas/data-science/using/conda_environ_list.htm
12+
INFERENCE_ENV_SLUG: dataexpl_p37_cpu_v2
13+
14+
# Replace with the type of environment. Either published or data_science.
15+
# Published environments are environments that you create and store in your own object storage bucket.
16+
# For more information: https://docs.oracle.com/en-us/iaas/data-science/using/conda_publishs_object.htm
17+
INFERENCE_ENV_TYPE: data_science
18+
19+
# Provide the Python version of the environment.
20+
INFERENCE_PYTHON_VERSION: 3.7

model_catalog_examples/artifact_boilerplate/score.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,20 @@
66
from cloudpickle import cloudpickle
77

88
"""
9-
Replace with your own model object and your own serialization library (e.g. pickle, onnx, etc).
9+
You can provide your own model object and your own serialization library (e.g. pickle, onnx, etc).
10+
If no model is specified then predict() by default will return 'Hello World!'
1011
"""
11-
model_name = 'model.pkl'
1212

13+
"""
14+
model_name = 'model.pkl'
15+
"""
1316

1417
"""
1518
Inference script. This script is used for prediction by scoring server when schema is known.
1619
"""
1720

1821

19-
def load_model(model_file_name=model_name):
22+
def load_model(model_file_name=None):
2023
"""
2124
Loads model from the serialized format
2225
WARNING: Please use the same library to load the model which was used to serialise it.
@@ -25,6 +28,8 @@ def load_model(model_file_name=model_name):
2528
-------
2629
model: a model instance on which predict API can be invoked
2730
"""
31+
if not model_file_name:
32+
return None
2833
model_dir = os.path.dirname(os.path.realpath(__file__))
2934
contents = os.listdir(model_dir)
3035
# --------------------------WARNING-------------------------
@@ -50,6 +55,8 @@ def predict(data, model=load_model()):
5055
predictions: Output from scoring server
5156
Format: {'prediction':output from model.predict method}
5257
"""
58+
if model is None or len(data) == 0:
59+
return {'prediction':'Hello world!'}
5360
from pandas import read_json, DataFrame
5461
from io import StringIO
5562
data = read_json(StringIO(data)) if isinstance(data, str) else DataFrame.from_dict(data)

0 commit comments

Comments
 (0)