Hugging Face Spaces: Gradio app and Node.js API tutorial

Build a background remover with Gradio, deploy it on Hugging Face Spaces with ZeroGPU, and call its API from a JavaScript app.

Player not loading? Watch on YouTube

This tutorial builds an image background remover with Gradio and deploys it on Hugging Face Spaces. The presenter creates a Space through the HF CLI, clones its repository, and writes a small Python application that passes an uploaded image to rembg. Gradio supplies the image input, output preview, and web interface.

The deployment uses ZeroGPU, selected in the Space's hardware settings before pushing the code. The presenter follows the build and container startup logs, then fixes a namespace typo: space.GPU should be spaces.GPU. A subsequent push triggers another build, and the application starts successfully. The web test uses an image with wispy hair to inspect the background removal result.

The second part connects a JavaScript application to the deployed API. Gradio's "use via API" link provides sample code. The presenter uses Gradio Client to connect to the Space and call the image-processing endpoint, then writes the returned image to a file with Node's filesystem APIs. Although this section describes a Node.js app, the demonstrated execution command uses Bun.

The example runs on Hugging Face's servers. The presenter describes this deployment as costing $0, while the client application runs on his computer.