How to Deploy A Face Detection Streamlit App on Heroku

In the previous tutorial,we saw how to build a simple face detection and image manipulation app with streamlit and opencv in python.

 

In this tutorial we will see how to deploy our app on heroku.  Deploying apps on heroku is quite simple, but you can face some issues when trying to deploy a computer vision  app such as face detection, face recognition apps on Heroku.

This is usually due to the fact that opencv requires some dependencies and libraries that do not come installed on your heroku dyno by default hence you will need to install it manually.

Let us see how to deploy our computer vision -face detection app on heroku.

Basic Requirements

Just as we learnt here, we need the 3 basic required files to deploy a normal app on heroku.

  1. Procfile
  2. setup.sh
  3. requirements.txt

You can then create an app using heroku CLI.

heroku create face-detection-stapp

and then you will be able to see the default page.

Okay your default page is showing but upon pushing your opencv face-detection app you will get an application error.

So how do you fix it. The error is  due to the fact that opencv requires some dependencies and libraries that do not come installed on your heroku dyno by default hence you will need to install it manually.

We will be using an Aptfile to help us fix it.

Requirements For Deploying OpenCV Face Detection Apps on Heroku

For opencv apps you will need an additional file called an Aptfile alongside the 3 basic files.

An Aptfile is a simple text file that contains packages and dependencies or libraries any how you call them that are normally installed using apt or apt-get. This file will tell heroku what to install using apt or apt-get.

By default your heroku account has a buildpack for apt but in case you do not have it you can check it and install one.

Checking If you have apt installed

Login into your account  and run Bash

heroku login
heroku run bash

Check if you have apt

apt

If you do not get any result you can use the following code to install buildpack-apt

heroku buildpacks:add --index 1 https://github.com/heroku/heroku-buildpack-apt

 

The next step is to include your dependencies on your Aptfile and add to your repository. Your Aptfile should include in our case (since we require dependencies for opencv) the following. On your Aptfile paste in the following

libsm6
libxrender1
libfontconfig1
libice6

Then add it to your github repository

git add Aptfile
git commit -m "Added Aptfile"
git push

 

After that you can push to heroku to deploy just as you would have done if you were deploying a normal app be it flask,streamlit or nodejs.

git push heroku master

Perfect! our app has now been deployed and it is functioning as we expected it to be.

You can check it out here

 

That is all for now. In case you want to get more on working with streamlit and ML apps you can check out this course for more.

Thanks For Your Time

Jesus Saves

Jesse E.Agbe(JCharis)

Leave a Comment

Your email address will not be published. Required fields are marked *