Example
Implementation
./iris-classifier
├── cortex.yaml
├── predictor.py
└── requirements.txtmkdir iris-classifier && cd iris-classifier
touch predictor.py requirements.txt cortex.yaml# predictor.py
import os
import pickle
from typing import Dict, Any
import boto3
from botocore import UNSIGNED
from botocore.client import Config
labels = ["setosa", "versicolor", "virginica"]
class PythonPredictor:
def __init__(self, config):
s3 = boto3.client("s3")
s3.download_file(config["bucket"], config["key"], "/tmp/model.pkl")
self.model = pickle.load(open("/tmp/model.pkl", "rb"))
def predict(self, payload: Dict[str, Any]) -> Dict[str, str]:
measurements = [
payload["sepal_length"],
payload["sepal_width"],
payload["petal_length"],
payload["petal_width"],
]
label_id = self.model.predict([measurements])[0]
# result must be json serializable
return {"label": labels[label_id]}Deploy
Monitor
Submit a workload
Retrieve the result
Stream logs
Delete the API
Last updated