Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/testdrivenio/fastapi-ml
deploying an ML model to Heroku with FastAPI
https://github.com/testdrivenio/fastapi-ml
fastapi fastapi-docker fbprophet heroku-deployment machine-learning
Last synced: about 2 months ago
JSON representation
deploying an ML model to Heroku with FastAPI
- Host: GitHub
- URL: https://github.com/testdrivenio/fastapi-ml
- Owner: testdrivenio
- License: mit
- Created: 2020-07-02T17:53:59.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-04-17T01:03:41.000Z (8 months ago)
- Last Synced: 2024-08-02T14:12:21.775Z (5 months ago)
- Topics: fastapi, fastapi-docker, fbprophet, heroku-deployment, machine-learning
- Language: Python
- Homepage:
- Size: 785 KB
- Stars: 46
- Watchers: 4
- Forks: 22
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-starred-test - testdrivenio/fastapi-ml - deploying an ML model to Heroku with FastAPI (Python)
README
# Deploying and Hosting a Machine Learning Model with FastAPI and Heroku
## Want to learn how to build this?
Check out the [tutorial](https://testdriven.io/blog/fastapi-machine-learning).
## Want to use this project?
### With Docker
1. Build and tag the Docker image:
```sh
$ docker build -t fastapi-prophet .
```1. Spin up the container:
```sh
$ docker run --name fastapi-ml -e PORT=8008 -p 8008:8008 -d fastapi-prophet:latest
```1. Train the model:
```sh
$ docker exec -it fastapi-ml python>>> from model import train, predict, convert
>>> train()
```1. Test:
```sh
$ curl \
--header "Content-Type: application/json" \
--request POST \
--data '{"ticker":"MSFT"}' \
http://localhost:8008/predict
```### Without Docker
1. Create and activate a virtual environment:
```sh
$ python3 -m venv venv && source venv/bin/activate
```1. Install the requirements:
```sh
(venv)$ pip install -r requirements.txt
```1. Train the model:
```sh
(venv)$ python>>> from model import train, predict, convert
>>> train()
```1. Run the app:
```sh
(venv)$ uvicorn main:app --reload --workers 1 --host 0.0.0.0 --port 8008
```1. Test:
```sh
$ curl \
--header "Content-Type: application/json" \
--request POST \
--data '{"ticker":"MSFT"}' \
http://localhost:8008/predict
```