Easily Deploy Python Computer Vision Models To The Web Using Hugging Face Spaces

George Davila Durendal
3 min readMay 24, 2022

--

Make your own gif using OpenCV here https://huggingface.co/spaces/GDavila/GIFify_OpenCV

In computer vision (CV) one of the most difficult tasks can be deploying and sharing models on the web. Especially when it comes to CV programs developed in python. There are options — like hoisting the model to the cloud — but those options often come at exorbitant costs in time or money. Over the last few years it has been exceedingly rare to see CV models deployed in a manner in which you can actually interact with them instantly. But what if we could interact with CV models instantly? No colab notebook, no downloading code and setting up an environment, just plain web inference.

That’s exactly what Hugging Face Spaces lets us do. We only need to build a UI in streamlit or gradio and put our code in an app.py file (and our dependencies in a requirements.txt file) and we can instantly put our CV programs on the web. To demonstrate this I created a space which uses an OpenCV script to convert any image into a colorful gif:

Refactored from this github repo of mine:

This is what the app will look like in your browser:

UI as shown on hugging face spaces

And it lets us turn static images like this:

into GIFs like this:

Make your own gif using OpenCV here https://huggingface.co/spaces/GDavila/GIFify_OpenCV

The Code

We can see that the app only consists of a relatively brief app.py:

and a requirements.txt referencing the dependencies opencv-python and Pillow.

The README is generated automatically in the spaces setup.

The algorithm itself generates copies of the image in different Hues (basically colors) and then patches those into a single gif. Hugging Face Spaces can retain saved files ephemerally so we can access them by loading them as outputs.

Make your own gif using OpenCV here https://huggingface.co/spaces/GDavila/GIFify_OpenCV

A Revolution in Computer Vision Accessibility

Web accessible CV models mean that new python CV engineers can interact and edit CV code more readily than ever before. This means that more people will be able to learn about the algorithms that go into machine learning based CV pipelines.

I’m George, a Stanford-Educated Tech Entrepreneur and A.I. Engineer. Follow me here on medium George Davila Durendal or over on LinkedIn for more tech & code.

--

--

George Davila Durendal

Diverse American A.I. Engineer + Tech Exec. Stanford Alum. Successful startup founder with 2 exits.