Skip to content

danielpoonwj/ml-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ml-api

This is a companion project to ml-models, a proof-of-concept workflow to expose predictive machine learning models as a HTTP API in Python 3.6.

This project relies on ml-models to define and generate trained models, and is essentially a thin wrapper allowing prediction capabilities to be utilized via a HTTP API.

Note: If any changes are made to ml-models, do edit requirements.txt to reference the correct branch/tag/commit.

Getting Started

Ensure that any required models are already trained and saved to local or S3 depending on the mode that you intend to run this project on. More information about the modes of operation can be found here.

This project can pass on any environment variables with a .env file. More information about the environment variables can be found here.

Installing

Docker

The simplest method to try this project out is through Docker.

The --env-file flag loads an optional file for environment variables which are required for operating in aws mode but not necessary for local mode.

The -v flag would attach a volume to allow the saved model previously generated by ml-models to be available from the host machine in local mode. This is not relevant for aws mode.

The -p flag publishes the container port to host. If you would like to change the mapping, do make the following change: -p 8080:{host_port}.

cd path/to/project

docker build -t temp/ml-api:latest .

docker run \
    --rm \
    -t \
    -p 8080:8080 \
    -v /tmp/ml_models:/tmp/ml_models \
    --env-file ./.env \
    temp/ml-api:latest

Local Python Virtual Environment

For development or running locally, a virtual environment is strongly recommended - I personally use pyenv.

If a .env file is present, the environment variables would automatically be applied in this process.

cd path/to/project

# create and activate Python 3.6 virtual environment

pip install -r requirements.txt

uwsgi --ini uwsgi.ini

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages