Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mdh266/dockermlrestapi

Machine Learning App As REST API with Docker & Google Cloud Run
https://github.com/mdh266/dockermlrestapi

data-science docker flask google-cloud machine-learning rest-api xgboost

Last synced: about 2 months ago
JSON representation

Machine Learning App As REST API with Docker & Google Cloud Run

Awesome Lists containing this project

README

        

# Dockerized Machine Learning Rest API
---------------------

Example of turning an [XGBoost](http://xgboost.readthedocs.io/) model (built [here](https://github.com/mdh266/NYCBuildingEnergyUse)) using [Flask](https://flask.palletsprojects.com/en/1.1.x/), [Docker](https://www.docker.com/) and [Google Cloud Run](https://cloud.google.com/run).

## Local Use
---------------

Build the image

docker build -t mlapp app

Run the API locally:

docker run -ip 8080:8080 mlapp

From Python:

data = {'columns': ['Energy_Star', 'Site_EUI', 'NGI', 'EI', 'Residential'],
'data': [[7744, 52.7, 45.9641802469, 10.1204555556, 1],
[9, 112.2, 25.9187489356, 29.7707095517, 1]]}

import requests

result = requests.post(url="http://0.0.0.0:8080/predict",
json=data)

result.json() # [0.0031427741050720215, 0.007205158472061157]

## Deploying to Google Cloud Run:
------------------------
Build image on Google Cloud:

cd app

gcloud builds submit --tag gcr.io//mlapp

Deploy to Google Cloud Run:

gcloud run deploy --image gcr.io//mlapp --platform managed