{"id":13572321,"url":"https://github.com/testdrivenio/fastapi-ml","last_synced_at":"2025-04-04T09:32:18.542Z","repository":{"id":41286374,"uuid":"276712446","full_name":"testdrivenio/fastapi-ml","owner":"testdrivenio","description":"deploying an ML model to Heroku with FastAPI","archived":false,"fork":false,"pushed_at":"2024-04-17T01:03:41.000Z","size":804,"stargazers_count":48,"open_issues_count":2,"forks_count":22,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-11-05T05:34:07.930Z","etag":null,"topics":["fastapi","fastapi-docker","fbprophet","heroku-deployment","machine-learning"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/testdrivenio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-07-02T17:53:59.000Z","updated_at":"2024-08-28T13:19:54.000Z","dependencies_parsed_at":"2024-04-17T02:25:46.866Z","dependency_job_id":"684f39ec-61b6-4332-b71d-eb3650601f29","html_url":"https://github.com/testdrivenio/fastapi-ml","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/testdrivenio%2Ffastapi-ml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/testdrivenio%2Ffastapi-ml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/testdrivenio%2Ffastapi-ml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/testdrivenio%2Ffastapi-ml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/testdrivenio","download_url":"https://codeload.github.com/testdrivenio/fastapi-ml/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247153994,"owners_count":20892771,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fastapi","fastapi-docker","fbprophet","heroku-deployment","machine-learning"],"created_at":"2024-08-01T14:01:20.081Z","updated_at":"2025-04-04T09:32:13.550Z","avatar_url":"https://github.com/testdrivenio.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# Deploying and Hosting a Machine Learning Model with FastAPI and Heroku\n\n## Want to learn how to build this?\n\nCheck out the [tutorial](https://testdriven.io/blog/fastapi-machine-learning).\n\n## Want to use this project?\n\n### With Docker\n\n1. Build and tag the Docker image:\n\n    ```sh\n    $ docker build -t fastapi-prophet .\n    ```\n\n1. Spin up the container:\n\n    ```sh\n    $ docker run --name fastapi-ml -e PORT=8008 -p 8008:8008 -d fastapi-prophet:latest\n    ```\n\n1. Train the model:\n\n    ```sh\n    $ docker exec -it fastapi-ml python\n\n    \u003e\u003e\u003e from model import train, predict, convert\n    \u003e\u003e\u003e train()\n    ```\n\n1. Test:\n\n    ```sh\n    $ curl \\\n      --header \"Content-Type: application/json\" \\\n      --request POST \\\n      --data '{\"ticker\":\"MSFT\"}' \\\n      http://localhost:8008/predict\n    ```\n\n### Without Docker\n\n1. Create and activate a virtual environment:\n\n    ```sh\n    $ python3 -m venv venv \u0026\u0026 source venv/bin/activate\n    ```\n\n1. Install the requirements:\n\n    ```sh\n    (venv)$ pip install -r requirements.txt\n    ```\n\n1. Train the model:\n\n    ```sh\n    (venv)$ python\n\n    \u003e\u003e\u003e from model import train, predict, convert\n    \u003e\u003e\u003e train()\n    ```\n\n1. Run the app:\n\n    ```sh\n    (venv)$ uvicorn main:app --reload --workers 1 --host 0.0.0.0 --port 8008\n    ```\n\n1. Test:\n\n    ```sh\n    $ curl \\\n      --header \"Content-Type: application/json\" \\\n      --request POST \\\n      --data '{\"ticker\":\"MSFT\"}' \\\n      http://localhost:8008/predict\n    ```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftestdrivenio%2Ffastapi-ml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftestdrivenio%2Ffastapi-ml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftestdrivenio%2Ffastapi-ml/lists"}