Skip to content

Latest commit

 

History

History
121 lines (87 loc) · 3.99 KB

README.md

File metadata and controls

121 lines (87 loc) · 3.99 KB

Read Through My Blog!

Pulsify

This is an artifact project where I mainly devoted my time to developing software endpoints. I also assisted in data cleaning and pre-processing. Check out the Team Repo for more!. For open-source purposes, I'm keeping this repository pinned so that others can learn from it and implement if they want. My blog post has more notes about what did , I highly recommend reading through it.

DS Build Week

Starter code to deploy your machine learning model as an API on Heroku. You can deploy a baseline in 10 minutes.

Tech stack

  • FastAPI: Web framework. Like Flask, but faster, with automatic interactive docs.
  • Heroku: Platform as a service, hosts your API.
  • Pipenv: Reproducible virtual environment, manages dependencies.

Getting started

Create a new repository from this template.

Clone the repo

git clone https://github.com/YOUR-GITHUB-USERNAME/YOUR-REPO-NAME.git

cd YOUR-REPO-NAME

Install dependencies

pipenv install --dev

git add Pipfile.lock

git commit -m "Add Pipfile.lock"

Activate the virtual environment

pipenv shell

Launch the app

uvicorn app.main:app --reload

File structure

.
└── app
    ├── __init__.py
    ├── main.py
    ├── routers
    │   ├── __init__.py
    │   └── predict.py
    └── tests
        ├── __init__.py
        ├── test_main.py
        └── test_predict.py

app/main.py is where you edit your app's title and description, which are displayed at the top of the your automatically generated documentation. This file also configures "Cross-Origin Resource Sharing", which you won't need to edit.

app/routers/predict.py defines an API endpoint /predict which currently returns random predictions. In a notebook, train your model and pickle it. Then in this file, unpickle your model and edit the predict function to return real predictions.

When your API receives a POST request, FastAPI automatically parses and validates the request body JSON, using the Item class attributes and functions. Edit this class so it's consistent with the column names and types from your training dataframe.

app/tests/test_*.py is where you edit your pytest unit tests.

More instructions

Install additional packages

pipenv install PYPI-PACKAGE-NAME

Launch a Jupyter notebook

jupyter notebook

Deploying to Heroku

Prepare Heroku

heroku login

heroku create YOUR-APP-NAME-GOES-HERE

heroku git:remote -a YOUR-APP-NAME-GOES-HERE

Deploy to Heroku

git add --all

git commit -m "Deploy to Heroku"

git push heroku main:master

heroku open

Deactivate the virtual environment

exit