Skip to content

This repo shows how to deploy a simple machine learning classification model following CI/CD principles with FastAPI on Heroku.

Notifications You must be signed in to change notification settings

HeberTU/deploy-ml-model-fastapi-heroku

Repository files navigation

Deploying a Machine Learning Model on Heroku with FastAPI

Code style: black

Repo Overview

This repository shows how to Deploy an end-to-end machine learning (ML) pipeline using FastAPI and Heroku.

See API documentation

The following directional graph shows the implemented ML-pipeline:

img_1.png

Which contains the following components:

  • prepare: preprocess the census data.
  • segregate: Segregates the data into test and training sets.
  • train: Trains a classification inference artifact.
  • evaluate: Test the fitted inference artifact.

How to Run Scripts

Dependencies Installation

  1. Create and activate a virtual environment for the project. For example:

    python3 -m venv ./.venv
    source ./.venv/bin/activate
  2. Install Poetry, the tool used for dependency management. To install it, run from a terminal:

    pip install poetry
  3. From the virtual environment, install the required dependencies with:

    poetry install --no-root

Execute Pipeline

The ML-pipeline can be executed:

dvc repro

Run API Locally

Type the following command to run the live server locally:

 uvicorn main:app --reload

Interactive API docs

Now go to http://127.0.0.1:8000/docs

You will see the automatic interactive API documentation: img.png

API

Documentation

The API has two endpoints, as shown in the API documentation.

GET - Root

The root domain contains a greeting and a helpful link where you can check the model card:

img_1.png

POST - Inference

This endpoint performs inference on new data:

img.png

About

This repo shows how to deploy a simple machine learning classification model following CI/CD principles with FastAPI on Heroku.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages