• Stars
    star
    356
  • Rank 119,446 (Top 3 %)
  • Language
    Jupyter Notebook
  • License
    Creative Commons ...
  • Created over 3 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

This is an example of a Containerized Flask Application that can deploy to many target environments including: AWS, GCP and Azure.

Python application test with Github Actions [Python application test with AWS Code Builde

Python MLOps Cookbook

This is an example of a Containerized Flask Application the can be the core ingredient in many "recipes", i.e. deploy targets..

mlops-color

Github Container Registery

Feel free to test my ML project: docker pull ghcr.io/noahgift/python-mlops-cookbook:latest

Assets in repo

Course2-Duke-Flask-Containerized

CLI Tools

There are two cli tools. First, the main cli.py is the endpoint that serves out predictions. To predict the height of an MLB player you use the following: ./cli.py --weight 180

predict-height-weight

The second cli tool is utilscli.py and this perform model retraining, and could serve as the entry point to do more things. For example, this version doesn't change the default model_name, but you could add that as an option by forking this repo.

./utilscli.py retrain --tsize 0.4

Here is an example retraining the model. model-retraining

Additionally the you can query the API via the CLI allowing you to change both the host and the value passed into the API. This is accomplished through the requests library.

./utilscli.py predict --weight 400

predict-cli

Flask Microservice

The Flask ML Microservice can be run many ways.

Containerized Flask Microservice Locally

You can run the Flask Microservice as follows with the commmand: python app.py.

(.venv) ec2-user:~/environment/Python-MLOps-Cookbook (main) $ python app.py 
 * Serving Flask app "app" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: on
INFO:werkzeug: * Running on http://127.0.0.1:8080/ (Press CTRL+C to quit)
INFO:werkzeug: * Restarting with stat
WARNING:werkzeug: * Debugger is active!
INFO:werkzeug: * Debugger PIN: 251-481-511

To serve a prediction against the application, run the predict.sh.

(.venv) ec2-user:~/environment/Python-MLOps-Cookbook (main) $ ./predict.sh                             
Port: 8080
{
  "prediction": {
    "height_human_readable": "6 foot, 2 inches", 
    "height_inches": 73.61
  }
}

Containerized Flask Microservice

Here is an example of how to build the container and run it locally, this is the contents of predict.sh

#!/usr/bin/env bash

# Build image
#change tag for new container registery, gcr.io/bob
docker build --tag=noahgift/mlops-cookbook . 

# List docker images
docker image ls

# Run flask app
docker run -p 127.0.0.1:8080:8080 noahgift/mlops-cookbook

Automatically Build Container via Github Actions and Push to Github Container Registery

To setup the container build process do the following. This is also covered by Alfredo Deza in Practical MLOps book in greater detail.

  build-container:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Loging to Github registry
      uses: docker/login-action@v1
      with:
        registry: ghcr.io
        username: ${{ github.repository_owner }}
        password: ${{ secrets.BUILDCONTAINERS }}
    - name: build flask app
      uses: docker/build-push-action@v2
      with:
        context: ./
        #tags: alfredodeza/flask-roberta:latest
        tags: ghcr.io/noahgift/python-mlops-cookbook:latest
        push: true 
    

container-registry

Automatically Build Container via Github Actions and Push to Dockerhub Container Registery

Build Targets

With the project using DevOps/MLOps best practices including linting, testing, and deployment, this project can be the base to deploy to many deployment targets.

[In progress....]

Other Tools and Frameworks

[In progress....]

FastAPI

AWS

Elastic Beanstalk

AWS Lambda Recipes

Install SAM as documented here, AWS Cloud9 has it installed already.

You can find the recipes here

AWS Lambda-SAM Local

sam-directory-layout

AWS Lambda-SAM Containerized Deploy

Follow recipe in recipe section.

sam-guided-deploy

When deployed an easy way to verify image is via Console.

invoke-lambda-console

A great way to test the API Endpoint is with the Cloud9 Environment:

invoke-api-gateway

Another way is the the tool "Postman":

post-man

AWS App Runner

Watch a YouTube Walkthrough on AWS App Runner for this repo here: https://www.youtube.com/watch?v=zzNnxDTWtXA

mlops

AWS Co-Pilot

Following setup here and then deploy project using cli https://docs.aws.amazon.com/AmazonECS/latest/developerguide/getting-started-aws-copilot-cli.html

GCP

Cloudrun (CaaS: Container as a Service)

It is trivial (if you select project):

gcloud config set project <yourprojectname>

A. Get GCP Account B. Checkout project C. cloud run deploy inside of project D. Verify it works by using ./utilscli.py

gcp-cloud-run

App Engine

GKE (Kubernetes)

Azure App Services

Production Patterns

[In progress....]

  • Cached model (deploy)
  • Load-testing

DataScience Workflow

mlb-ht-wt

This repository is focused on MLOps. To see more about Data Storytelling, you can go to this Github repo on Data Story Telling

Next Steps: Take Coursera MLOps Course

cloud-specialization

More Repositories

1

functional_intro_to_python

[tutorial]A functional, Data Science focused introduction to Python
Jupyter Notebook
300
star
2

awslambda

AWS Lambda
Jupyter Notebook
214
star
3

python-devops-course

A repo for a course on Python DevOps
Jupyter Notebook
175
star
4

pragmaticai

[Book-2019] Pragmatic AI: An Introduction to Cloud-based Machine Learning
Makefile
117
star
5

cloud-data-analysis-at-scale

[Course-2020-2023] taught at Duke MIDS. This is also a Coursera Course that covers MLOps, ML Engineering and the foundations of Cloud Computing for Data Science.
Jupyter Notebook
115
star
6

aws-ml-guide

[Video]AWS Certified Machine Learning-Specialty (ML-S) Guide
Jupyter Notebook
114
star
7

flask-ml-azure-serverless

Deploy Flask Machine Learning Application on Azure App Services
Python
72
star
8

real_estate_ml

Machine Learning for Real Estate
Jupyter Notebook
62
star
9

myrepo

continuous integration rep
Jupyter Notebook
45
star
10

edge-computer-vision

Edge Computer Vision Course
Jupyter Notebook
42
star
11

mlflow-project-best-practices

An example MLFlow project
Jupyter Notebook
41
star
12

aws-cloud-practitioner-exam

[Course]Study Material for AWS Cloud Practitioner Exam
Python
41
star
13

aws-bootcamp

A Graduate Level Three Week Bootcamp on AWS
41
star
14

noahgift

Noah Gift Github Profile
41
star
15

managed_ml_systems_and_iot

Managed Machine Learning Systems and Internet of Things Live Lesson
Jupyter Notebook
35
star
16

data-engineering-and-dataops

Duke MIDS: Data Engineering and DataOps Course
HTML
34
star
17

docker-flask-locust

A docker + flask + locust demo project
Python
34
star
18

serverless-cookbook

Some recipes for doing with serverless technologies
Python
33
star
19

github-actions-pytest

Example Github Actions Directory
Python
33
star
20

github-actions-demo

This is a repo for building out Github Actions and Tricks
Makefile
33
star
21

mlops-duke-aipi

Syllabus for Artificial Intelligence for Product Innovation Master of Engineering: https://ai.meng.duke.edu/degree
30
star
22

function-bike-rider

This is a repo for showing what you can do with a function
Python
28
star
23

devml

Product of Pragmatic AI Labs: Machine Learning, Statistics and Utilities around Developer Productivity, Company Productivity and Project Productivity
Jupyter Notebook
27
star
24

socialpowernba

Social Power in the NBA (Comparing on the court performance with Social Influence in R and Python)
Jupyter Notebook
27
star
25

spot_price_machine_learning

Machine Learning for Spot Prices
Jupyter Notebook
26
star
26

container-revolution-devops-microservices

DevOps SKlearn Microservice
Makefile
26
star
27

web_scraping_python

Techniques for Scraping the Web in Python
Jupyter Notebook
23
star
28

python-for-devops-april-2022

This is a new repository for Python for DevOps Lecture/Workshop
Jupyter Notebook
23
star
29

kubernetes-hello-world-python-flask

A Kubernetes Hello World Project
Python
23
star
30

databricks-zero-to-mlops

Python
22
star
31

Flask-Elastic-Beanstalk

Python
21
star
32

fastapi

Demo of FastAPI
Python
20
star
33

flask-change-microservice

Small Flask Microservice that makes the change
Python
20
star
34

python-data-engineering-cookbook

Some recipes for data engineering with Python
Python
20
star
35

pytest-tips-tricks

A primer on pytest
Python
18
star
36

container-from-scratch-python

This is building a container from scratch
Dockerfile
17
star
37

boston_housing_pickle

An example repo that pickles out a sklearn model
Jupyter Notebook
14
star
38

azure-ml-devops

Azure DevOps workflow for ML
Python
14
star
39

rust-new-project-template

A good starting point for a new Rust project
Makefile
14
star
40

gcp-flask-ml-deploy

This is a project to auto-deploy with an ML payload
Python
13
star
41

or

Operations Research Algorithms
Python
13
star
42

rdedupe

A Rust based deduplication tool
Rust
12
star
43

gcp-hello-ml

Jupyter Notebook
12
star
44

functions-from-zero

live training
Jupyter Notebook
12
star
45

pytest-from-ground-zero

This is a new pytest repo that covers the best practices
Python
11
star
46

data-story-telling

A repo where I explain how to do data story telling
Jupyter Notebook
11
star
47

CLI-Bootcamp

Ideas on how to quickly learn to build command-line tools
Jupyter Notebook
10
star
48

continuous-integration

This is a sample repo
Makefile
10
star
49

pragmaticai-gcp

Pragmatic AI solutions on GCP
Jupyter Notebook
10
star
50

pass-any-aws-exam

How to pass any
9
star
51

nuclear_powered_command_line_tools

Nuclear Powered Command-Line Tools
Jupyter Notebook
9
star
52

dukehugofeb1

this is a Hugo continuous delivery site
9
star
53

python-for-devops-may-2022

From Zero Repository for doing Python DevOps work
Jupyter Notebook
9
star
54

core-stats-datascience

Core Statistics for Datascience
Jupyter Notebook
9
star
55

aws-step-functions

Brief Tutorial on AWS Step Functions
Python
8
star
56

pragai-aws

Chapter 2 on AWS for Pragmatic AI
Jupyter Notebook
8
star
57

tensorflow-m1-setup

Notes on Tensorflow with Mac M1
Jupyter Notebook
8
star
58

DevOps-Best-Practices

This is an example of a DevOps Repo that conforms to best practices
Python
7
star
59

DotNet-AWS

Resources and Examples of .NET on AWS
Shell
7
star
60

eks-fargate-tutorial

A tutorial on using EKS with fargate on the AWS Cloud
Python
7
star
61

hugotools

Some tools I have created to use hugo
Python
7
star
62

distributed-computing-explorations

Some ideas around concurrency and distributed computing
Jupyter Notebook
6
star
63

intermittent-fasting

Data Science around intermittent fasting
Jupyter Notebook
6
star
64

python-click-cli-cookbook

A repo with a cookbook of recipes for building command-line tools with Python Click
Python
6
star
65

codespace-devops

This is a Python for DevOps Codespace Repo
Python
6
star
66

mlops-certifications

6
star
67

logging-monitoring-instrumentation

A brief repository on logging monitoring and instrumentation in Python
Python
6
star
68

cloud-bash-essentials

Essentials for using Bash in the Cloud
6
star
69

scaffold

this is a project scaffold for Python
Makefile
5
star
70

fundamentals_ai_ml

Pearson Video on Fundamentals of AI/ML
Jupyter Notebook
5
star
71

get-certified-google-cloud

Python
5
star
72

computer-vision-api

This is a repo for creating Computer Vision examples
Python
5
star
73

flask-hello-coursera

Hello world Flask app for a Coursera Course: Cloud Computing for Data.
Python
5
star
74

Apple-CreateML-AutoML-Recipes

Some recipes around Apple CreateML
Jupyter Notebook
5
star
75

exploratory-data-analysis

EDA ideas
Jupyter Notebook
5
star
76

DevOps-2022

This is a repo for DevOps
Python
5
star
77

py4sa

This is the source code for a book I co-authored on Python for Systems Administration for O'Reilly
Python
5
star
78

ml-engineer-certification

Notes on Google ML Engineer Certification
5
star
79

devops-for-mlops

This demonstrates the core ideas of DevOps
Makefile
5
star
80

cloud-devops-demo-march13

This is a demo of how to setup a repo with Continuous Integration
Python
4
star
81

Python-Functions-from-Zero

this is a repo for building Python functions from Zero
Python
4
star
82

flask-tensorflow-image-classification

Image Classification Example using Flask and Tensorflow
4
star
83

github-actions-hello-world

Hello World
Makefile
4
star
84

microservice

This is an example Microservice
Python
4
star
85

bash-scripts

Examples of Bash Scripts
Shell
4
star
86

model-explainability

A model explainability walkthrough
Jupyter Notebook
4
star
87

rust-docker-cli

An example of Rust command-line tool running inside a Docker container
Rust
4
star
88

52-weeks-swift

Weekly Podcast/Livestream on Apple Swift Language
Swift
4
star
89

enterprise-mlops-book

Source Code Examples from the O'Reilly Book Enterprise MLOPs 2023
4
star
90

regression-concepts

Regression Concepts
Jupyter Notebook
4
star
91

flask-random-fruit

A flask microservice for generating random fruit!
Python
4
star
92

MLConcepts

Jupyter Notebook
4
star
93

python-functions-9-23

This is a new repo for a live training by O'Reilly
Jupyter Notebook
4
star
94

multicloud-devops-lifecycle

AWS+Google+Azure
Python
4
star
95

sugar

Nutrition Data Science exploration of Sugar
Jupyter Notebook
4
star
96

common-linux-commands-data-engineering

A few examples of common Linux Commands for Data Engineering
Shell
3
star
97

cloud-shell-lambda-tricks

Shell
3
star
98

tech-solopreneurship

Notes on technology solopreneurship
3
star
99

oreillydemopytest

Jupyter Notebook
3
star
100

microservices-key-concepts

Key Concepts in Microservices
Python
3
star