Skip to content

Deploying and Hosting a Facebook Prophet Forecasting Model with FastAPI and Heroku

Notifications You must be signed in to change notification settings

astrogopher/fastapi-fbprophet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Deploying and Hosting a Machine Learning Model with FastAPI and Heroku

Want to learn how to build this?

Check out the post.

Want to use this project?

With Docker

  1. Build and tag the Docker image:

    $ docker build -t fastapi-prophet .
  2. Spin up the container:

    $ docker run --name fastapi-ml -e PORT=8008 -p 8008:8008 -d fastapi-prophet:latest
  3. Train the model:

    $ docker exec -it fastapi-ml python
    
    >>> from model import train, predict, convert
    >>> train()
  4. Test:

    $ curl \
      --header "Content-Type: application/json" \
      --request POST \
      --data '{"ticker":"MSFT"}' \
      http://localhost:8008/predict

** Note, I built this with guidance from https://medium.com/geekculture/from-apple-silicon-to-heroku-docker-registry-without-swearing-36a2f59b30a3 using Option A:buildx as I use Apple M1 Chip which is based on the ARM architecture. **

In order to create a x86 compatible image, the solution is NOT to use the heroku:container push command but rather building the image locally with Docker buildx

docker buildx build --platform linux/amd64 -t desolate-plateau-08735 .
# tag image to match Heroku naming conventions
docker tag desolate-plateau-08735 registry.heroku.com/desolate-plateau-08735/web
# push
docker push registry.heroku.com/desolate-plateau-08735/web

Once pushed, the image can then be released

heroku container:release web -a desolate-plateau-08735

Without Docker

  1. Create and activate a virtual environment:

    $ python3 -m venv venv && source venv/bin/activate
  2. Install the requirements:

    (venv)$ pip install -r requirements.txt
  3. Train the model:

    (venv)$ python
    
    >>> from model import train, predict, convert
    >>> train()
  4. Run the app:

    (venv)$ uvicorn main:app --reload --workers 1 --host 0.0.0.0 --port 8008
  5. Test:

    $ curl \
      --header "Content-Type: application/json" \
      --request POST \
      --data '{"ticker":"MSFT"}' \
      http://localhost:8008/predict

About

Deploying and Hosting a Facebook Prophet Forecasting Model with FastAPI and Heroku

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published