Skip to content

A prediction API hosted on Azure app service, continuously integrated & deployed.

License

Notifications You must be signed in to change notification settings

rafaelschlatter/pipedesign-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pipedesign-api

Build Status codecov Requirements Status Codacy Badge Code style: black

About

This is a python flask API that is hosted on Microsoft Azure app service. The API allows to activate pickled machine learning models from an Azure blob storage and request predictions on new data. The API can be tested using the Swagger ui here: http://pipedesign.azurewebsites.net/.

Setup

Azure app service on linux needs a requirements.txt file for all dependencies except flask. A pipenv workflow probably fails (not tested).

Clone the repo and create a virtual environment with virutalenv:

git clone https://github.com/rafaelschlatter/pipedesign-api.git
cd pipedesign-api
virtualenv pipedesign-api

Activate it and install dependencies:

source pipedesign-api/bin/activate
pip install -r requirements.txt

You need to set the following environment variables:

STORAGE_ACC_NAME=<your-storage-account-name>
BLOB_KEY1=<your-storage-account-key>
CONTAINER_NAME_DATA=<container-name-containing-training-data>
CONTAINER_NAME_MODELS=<container-name-containing-models>
APPINSIGHTS_INSTRUMENTATIONKEY=<application-insights-instrumentation-key>

Run tests locally and produce coverage report (all or a specific file):

python -m pytest -v --cov=src
python -m pytest tests/infrastructure/blobhandler.py -v --cov=src

Usage

Run the app locally with the following command at the root folder:

python application.py

You can also try the app hosted on Azure. The following code demonstrates usage with valid json data in python 3. Start a terminal at the root folder and run the following code:

import requests, json

# Activate pickled model from Azure blob storage
activate_url = "http://pipedesign.azurewebsites.net/model/activate_pickled/test_model_1_do_not_delete/"
requests.put(url=activate_url)

# Retrieve prediction on pipedesign
predict_url = "http://pipedesign.azurewebsites.net/prediction/predict_pickled/"
with open("data/json/0a234fea9682454facab730c0a7f83f0.json") as f:
    json_data=json.load(f)

response = requests.post(predict_url, json=json_data)
print(response.json())

If there is a trained model available, you should get the following response:

{
    "confidence": "0.00985992289985627",
    "label": "1",
    "pipedesign_id": "0a234fea9682454facab730c0a7f83f0",
    "prediction": "Viable"
}

About

A prediction API hosted on Azure app service, continuously integrated & deployed.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages