In Model Deployment with Flask/Part-2, we will take the steps to make our model run on the web. As you remember from the Model Deployment with Flask/Part-1, we covered the definition of Machine Learning Pipeline and model deployment then created necessary files for model deployment.
In this story, at first, we will check whether our model works properly, then upload the necessary files to GitHub, and finally create an app on Heroku.
Step-1: Testing Our Model Locally
Before uploading files to GitHub and then Heroku, it is better to check our model locally. We can do it by running the python app.py command. Anaconda Prompt to run the model
Then we copy the URL from the prompt and paste it into a web browser. Finally filling the form provided, we can click on the submit button to see whether our app is working properly or not. Checking the App Locally
If everything goes as expected, we can pass to the second step.
Step-2: Creating a GitHub Repository to Upload Required Files
Now it is time to upload the files we created in Part-1 to GitHub. First, let’s remember these files:
- HTML (named as index.html in templates folder)
We can upload files to GitHub via either a command line or a browser. Since files you want to add a repository via a browser must be limited to 25 MB per file, a command line should be used for larger files.
I created a GitHub repository, named model_deployment, and uploaded all the necessary files to it via a browser.
Now we can pass to the last step.
Step-3: Creating the App on Heroku
Heroku is a container-based cloud Platform as a Service (PaaS) that enables users to deploy and manage their apps. Heroku platform is very flexible, easy to use, and offers users a simple and easy way to run their apps on the web.
In order to use Heroku, you need to create an account at https://signup.heroku.com/.
Heroku offers different methods to deploy your model. We will cover model deployment with Heroku CLI and GitHub connection.
If you want to deploy your model using Heroku CLI, first you need to download Heroku CLI and then follow the steps below in the command line.
- heroku login
- heroku create <app name>
- git init
- git add .
- git commit -m “deployment”
- git push heroku master
- heroku open
Another method is to deploy your model via a GitHub connection to Heroku.
- First login to your Heroku account.
- Click on “New” and then “Create new app”.
- Give your app a proper name and click on “Create app”.
- Choose GitHub as a Deployment method.
- Enter the name of the GitHub repo you have created to deploy your model, and click on “Search”.
- When you see the repo, click on the “Connect” button.
- Finally, click on the “Deploy Branch” button and your app will automatically be uploaded to Heroku.
Creating the app on Heroku
You can check your model by clicking on the “View” button and this time try it on the web.Checking the app
Final Thoughts on Model Deployment with Flask
In this two-part story, we covered the machine learning pipeline, necessary files for model deployment, and finally followed a step by step approach to create a web application using Flask on Heroku.
Heroku’s easy to use platform provides an amazing opportunity to prototype the final product. By taking this opportunity, we were able to run our app on the web.
You have created your first app on the web and met with Heroku. Now it is time to create some other apps!
Last Updated on August 5, 2023