Create a virtual environment.
python -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip wheel setuptools
python -m pip install -r requirements.txt
The script train-and-deploy.py
will train and deploy the model as REST API to Connect. Run the script using the following:
python train-and-deploy.py
Note the Direct content URL
printed in the output. Export it as an environment variable MODEL_URL
.
export MODEL_URL="https://colorado.posit.co/rsc/content/c2f189da-7626-48e7-9882-78ee6c49c1b9"
The notebook make-predictions.ipynb includes examples of how to call the model API endpoint using Python.
From the shell with no API key:
curl -X POST "${MODEL_URL}/predict" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-d '{"cyl":0,"disp":0,"hp":0,"drat":0,"wt":0,"qsec":0,"vs":0,"am":0,"gear":0,"carb":0}'
From the shell using an API key:
curl -X POST "${MODEL_URL}/predict" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Key ${CONNECT_API_KEY}" \
-d '{"cyl":0,"disp":0,"hp":0,"drat":0,"wt":0,"qsec":0,"vs":0,"am":0,"gear":0,"carb":0}'