In this workshop, you will learn how to build a machine learning model using Python/Scikit-Learn, turn the model into an API using Python/Flask, test the API, build web applications using HTML/CSS/JavaScript/Nextjs, and deploy it to the web for global usage by end-users.
MIT License
One essential and last phase of the CRISP-DM data framework is deployment. The key focus in this phase is the usability of the developed model by intended users or customers. Depending on the type of solution and use case, this can involve deploying and integrating the model on any medium like the web, a mobile application, a hardware-embedded system, etc. While this might "sound easy,” many beginner ML engineers find it daunting to deploy their projects on the web for their intended users to test and for their solutions to solve their users' problems.
In this workshop, Bolaji will introduce you to machine learning model deployment by showing you the steps and processes involved with turning a machine learning model into an API with Python and Flask, testing the API with Postman, building a web application, and deploying it to the cloud for global usage. We would also discuss several other alternative Python/JavaScript frameworks and tools to consider.
This repository contains the workshop materials, lesson notes, machine learning model notebooks, serilized models, backend API/web application code, and links to further resources. You can follow the workshop lessons and build the project yourself or use the materials to learn at your own pace.
In this workshop, we will build the following:
/model
)./app/flask-api
)./app/flask-app
)./app/nextjs-flask-app
).You can test the deployed applications here:
flask-api
: https://mbpti-flask-api.fly.dev.flask-app
: https://mbpti-flask-app.fly.dev.Workshop duration: ~three (3) hours.
At the end of this workshop; you should be able to:
This workshop has been presented at the following events:
Generally, you need the following:
To make the workshop a smooth process, we will use Google Colab for the machine learning model development. This will enable us to run a hosted Jupyter Notebook on the cloud (with GPU and TPU computing resources) and avoid issues with installing all the Python packages locally (the future is cloud!). All you have to do is create a free Google account if you don't have one already and open the Notebook in Google Colab.
But if you prefer local (I strongly advise against this; at least for this workshop), you should install Anancoda to use Jupyter Notebook on your local computer. You will need to install and import all the required packages yourself too and resolve any conflicts that might arise.
[!NOTE]
Jupyter Notebooks allow you to combine executable code and rich text in a single document, along with images, HTML, LaTeX, and more.
You should have the following software and packages installed on your computer. Kindly follow the guide in each toggle to install them.
We will install/use the following packages:
Download and install Git from this website for all operating systems or follow this installation guide.
Once installed successfully, confirm the version using the command:
git --version
Next, create a free GitHub account if you don't have one already.
[!NOTE]
Bonus: If you're a student, you should check out the GitHub Student Developer Pack, which gives students free access to the best developer tools (paid tools/services/courses for free) in one place so they can learn by doing.
We will install any of the following:
Download and install the Postman Desktop Client or VSCode Extension from this website for all operating systems.
We will install the following packages:
Download and install Python 3 (>3.10.12
) from this website for all operating systems (this will come with PIP in-built).
[!IMPORTANT]
Please specifically download and install a version
3.10.12
or higher (I'm using3.11.5
). Google Colab will install version3.10.12
which we will use to develope a machine learning model and anything less on your local machine will result in errors when using the serilized model.
Once installed successfully, confirm the version using the command:
python3 --version
If Python is installed correctly, you should have PIP installed. If it isn't, follow the steps in this guide to install PIP.
We will install the following packages:
.env
file and can set them as environment variables.[!IMPORTANT]
Eventually, we will install the above mentioned libraries in a virtual environment to ensure we use independent groups of Python libraries for each project. This is a recommended practice when building Python aplications in both development and production.
In the project directory, create the environment with the command python3 -m venv .venv
and activate the envirnment with the command source .venv/bin/activate
.
Now, install all of the packages using the command below:
pip3 install python-dotenv scikit-learn flask gunicorn
Once installed successfully, confirm the version using the command:
pip3 show python-dotenv
pip3 show scikit-learn
pip3 show flask
pip3 show gunicorn
We will install the following packages:
Download and install Nodejs and NPM from this website for all operating systems or follow this installation guide.
Once installed successfully, confirm the version using the command:
node --version
npm --version
We will install the following packages:
Automatically create a project with the latest version of Reactjs18 and Nextjs13 using the create-next-app
command below:
npx create-next-app@latest
Consider reading Reactjs's installation guide to learn more.
We will install the following packages:
Sign up for a free account on Fly.io and Vercel if you haven't yet. Next, read this guide to install flyctl
for any operating system.
flask-api
app to support CORS, change how we get the request data, deploy to Fly again, and then use the live API directly in the Nextjs app.Fork this repository (learn how to do this here).
Clone the forked repository like so:
git clone https://github.com/<your username>/deploy-ml-web-workshop.git && cd deploy-ml-web-workshop
Make your changes and create a pull request (learn how to do this).
I will attend to your pull request, provide some feedback, request some changes, or eventually merge the PR!
The content of this repository © 2023 by Bolaji Ayodeji is published under the Creative Commons Attribution-ShareAlike 4.0 International license and the underlying code examples are licensed under the MIT license.