Do you want to deploy your Python code to web for free? Read this post to know the step-by-step procedure to host your web app for free on Heroku cloud.

Deploying a Machine Learning model is a difficult task due to the requirement of large memory and powerful computation. This tutorial focuses on a simple deployment technique that can be used to deploy any Python web app for free.

Read my previous article to learn how to build an “Image classification web app with FastAPI and Tensorflow”

If you prefer a video tutorial then click on the video below:

Step 1

First of all, you will need a Heroku id, so go now and register for a free account.

For deploying any Python app on Heroku, we need three files- requirements.txt, runtime.txt, and Procfile.

requirements.txt is a normal text file that contains Python packages required to run the app.

runtime.txt is a text file that will contain the Python Version you want your app to run on.

Procfile will contain the command to launch your web app. For example, you can use

method 1
`python application/server/main.py`

or uvicorn if you are deploying a uvicorn server
`uvicorn application.server.main:app`

Step 2

Go to your Heroku dashboard then click on New and create a new app


Enter your App name and select the Server region that is nearest to your location and click on Create app


Step 3

After you create the app, you will see the deployment methods — Heroku Git, GitHub, and Container Registry. I will use the GitHub method. For this just push your code repository to your GitHub account and then connect to GitHub on Heroku.

Then search the repository and connect it to your Heroku app.

After this, you will see a deploy button, select the branch of your Git repository that you want to be deployed, and click on deploy.

Then Heroku will automatically start your deployment 🎉🎉 After deployment, you can access your app from any web browser 🔥



Hope this article helped you in the deployment of your web app. If you have some feedback or suggestion please let me know in the comment section.

Follow me on Twitter: https://twitter.com/aniketmaurya

Subscribe to my YouTube channel: https://www.youtube.com/channel/UCRuFsj94hWecPkuEr4f5Xww