Hosting Machine Learning apps easily and freely via Hugging Face Spaces
Apr 26, 2022
Alexander Junge
3 minute read

Data science and machine learning (ML) projects frequently involve prototyping models as part of ML apps, showing them to potential users to get feedback, and iterating to improve both model as well as problem-solution fit. Tools like Gradio and Streamlit make it easy to develop visually appealing ML apps with a few lines of code. Making these apps available to users is unfortunately not trivial and usually involves paying for cloud hosting and overcoming various technical hurdles.

Hugging Face Spaces allows you to host and share ML apps easily and for free. Here is an example from a recent hobby project:

Example app computing patent phrase similarity running on Hugging Face Spaces

The app is available on this Hugging Face Space. The underlying code is on GitHub and I am using GitHub Actions to keep code and app in sync.

I built this sample app using Gradio within a few hours. It scores the semantic similarity of pieces of text from U.S. patents. Similarity scores are between 0 and 1; higher scores mean higher similarity. A score is defined as the cosine similarity of the phrase-wise embeddings produced by the AI-Growth-Lab/PatentSBERTa SentenceTransformer model and could be used for down-stream tasks like clustering or search ranking. The app and its examples are based on the Google Patent Phrase Similarity Dataset used in the ‘U.S. Patent Phrase to Phrase Matching’ Kaggle competition.

This simple app is not tweaked for performance - neither from an ML nor from a inference time perspective - but rather as an example of what’s with a few lines of code (around 45 currently).

Workflow for deploying the app via GitHub Actions

Deploying the app was simple and involved the following steps:

  • Create a new Space https://huggingface.co/new-space.
  • The Space comes with a git repository which I cloned to my machine. Since I wanted to use GitHub as the primary repository location for my code, while setting up a GitHub Action to keep the deployed app in sync, I set up my .git/config with two remote locations - ‘origin’ pointing to the GitHub repository and ‘space’ pointing to the Space repo, e.g.:
[remote "origin"]
        url = git@github.com:JungeAlexander/uspppm-demo.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[remote "space"]
        url = https://huggingface.co/spaces/jungealexander/uspppm-demo
        fetch = +refs/heads/*:refs/remotes/space/*

Summary

Spaces makes it possible to host ML app protoypes and to showcase your work to the world - give it a try, it’s free and easy to get started.



comments powered by Disqus