How to Use Hugging Face Spaces for AI Applications | Easy Background Removal & Image Generation

Hugging Face Spaces lets you run AI models like background removal and Stable Diffusion through a web interface, no downloads or API tokens required. Here is how to use it and when it makes sense.

6:53 video4 min readWatch on YouTube

Downloading a model, installing dependencies, and managing an API token just to test whether an AI tool does what you need is a lot of overhead for a quick experiment. Hugging Face Spaces exists to skip that step entirely, letting you interact with a model through a web interface instead of setting up the whole pipeline yourself. This walkthrough covers what Spaces is for and demonstrates it with two concrete examples: removing an image background and generating an image from scratch.

What Hugging Face Spaces actually is

Hugging Face Spaces is a cloud platform that enables developers, researchers, and organizations to deploy and share machine learning applications. It's built around easy deployment, interactive demos, collaboration, custom domains, and scalability, with security built in. The supported frameworks are Gradio, Flask, and FastAPI, which cover most of what you'd need to wrap a model in a usable interface.

When to reach for Spaces instead of downloading a model

There are two clear use cases. The first is prototyping: when you want to develop a proof of concept, try something out, or let other people use a model without asking them to set anything up locally. The second is product showcasing, launching an interactive demo so customers can try a product and understand what it does firsthand. In both cases, the alternative, downloading a model, pip-installing it, and managing an API token, is exactly the overhead Spaces removes. Instead of that setup, you can search for a Space that already wraps the model you need, in a sentiment analysis example, and just enter your input directly.

Demo one: Stable Diffusion for image generation

The first hands-on example is Stable Diffusion, a model used to generate high-quality images. It's based on latent diffusion, with the key improvement being that latent diffusion features are compressed while Stable Diffusion refines and improves on that foundation. Practically, that means giving Stable Diffusion an accurate, detailed prompt produces an accurate, detailed image in return.

The demonstrated prompt asked for a realistic, cozy morning breakfast setting: soft natural light in a kitchen, a wooden table set with a jar of strawberry jam as the centerpiece, surrounded by freshly baked croissants, butter, and a steaming cup of coffee. The level of detail in that prompt is deliberate. Stable Diffusion has been trained on millions of image and prompt pairs, so it already understands what you're asking for when the prompt is specific; the accuracy of the output tracks the accuracy and specificity of the prompt you give it.

Running the generation and adjusting settings

Generating an image on Spaces uses GPU compute behind the scenes, and a free account comes with a limited number of GPU requests per day. Beyond the prompt itself, there are adjustable settings: image width and height, the guidance scale, and the number of steps the model iterates through before producing the final image, along with a seed value. In the demonstrated run, the resulting image matched the prompt closely, including the human element (a hand), the strawberries worked into the croissants, and visible steam rising convincingly from the coffee cup. Stable Diffusion isn't the only model available for this kind of generation, but it's presented here as one of the strongest options currently available, arguably more accurate for this kind of prompt than some alternatives.

Demo two: background removal

The guide's second example uses a background removal model, Rembg, following the same pattern: no download, no local setup, just uploading an image and letting the Space handle the processing. This is the kind of task that's tedious to set up from scratch but trivial once it's wrapped in a Spaces interface.

Beyond generation: what else Stable Diffusion-style models can do

Text-to-image generation, giving a realistic, accurate prompt and getting a matching image back, is the core capability, but it's not the only one available through this kind of model. Image-to-image transformation lets you modify, enhance, or restyle an existing image based on a new prompt. Inpainting restores or replaces specific parts of an image while preserving everything else's overall appearance. Both are available through the same kind of Spaces interface as the text-to-image example.

Key takeaways

  • Hugging Face Spaces deploys machine learning models behind a web interface, so you can use them without downloading, installing, or managing API tokens.
  • It's built for two main use cases: prototyping proof-of-concept ideas and showcasing interactive product demos.
  • Supported frameworks are Gradio, Flask, and FastAPI.
  • Stable Diffusion image quality tracks prompt specificity directly; a detailed, accurate prompt produces a detailed, accurate image.
  • Generation settings you can adjust include image width and height, guidance scale, number of steps, and seed.
  • Beyond text-to-image, the same category of model supports image-to-image transformation and inpainting.

Who this is for

This is a good starting point for developers, researchers, or anyone AI-curious who wants to try powerful models like Stable Diffusion or a background removal tool without writing setup code. A fuller tutorial with code examples covering both the background removal and Stable Diffusion workflows is available from Humanitarians AI Fellows for anyone who wants to go deeper after this walkthrough.

Full transcript(auto-generated, with timestamps)

[0:02]Hi all, this tutorial is about hugging face spaces. In the previous video which is the hugging face tutorial, we talked about the first two components which is data set and models. In this we will be talking about hugging face and spaces. To give you an introduction, hugging face spaces is a cloud platform and it enables developers, researchers and organizations to deploy and share machine learning applications. It focuses on easy deployment, interactive demos, collaborations, custom domains, securable and it is scalable. When do we use hugging face spaces? When you want to prototype or develop, you want to develop proof of concept of applications. You want to try something

[0:49]Out, you want to create a model where other you want other people to use it. That's when you use hugging face spaces. Also, like I said, product showcases, it's the same like you want to interact, launch an interactive product demo for customers and you want to people to try it and understand it. That's when you use hugging face spaces and the supported frameworks are gradu flask and fast API. So now we will move on to the next component which is the hugging face spaces. So hugging face spaces like we said has multiple models and data sets. Now you have to download these models use it and

[1:31]Then write a code for it and more. So instead of that we have hugging face spaces. What hugging face spaces helps you is that it helps it's like a cloud platform that enables developers, researchers and organizations to deploy and share their models and people can access these models and use them. For example, like the sentiment analysis I had to download and then I had to pip install it. I or I had to give my API token and then use it. Instead of that I can just search the space for a sentiment analysis model and I can just enter my statements there and then it will give you. So it helps

[2:15]You um avoid all the initial steps and go directly to what your task is. For example, I want to show you uh about stable diffusion. Now stable diffusion is a model that you use to generate high quality images. It is based on latent diffusion but latent diffusion features are very low and it is an improved version of latent diffusion. So using stable diffusion you can just give an accurate prompt of what you need and it will um accurately give you or develop the image. So here if you go into stable diffusion and I'm going to enter my prompt. So my prompt if you see I want a

[3:04]Realistic cozy morning breakfast setting with soft natural light pouring into the kitchen. A wooden breakfast table is set with this jar of strawberry jam as the centerpiece surrounded by props like freshly baked croissants, butter, and a steaming cup of coffee. You see how accurate my prompt is? You have to give these prompts very accurately in order for the model to understand. So this stable diffusion model has been trained on millions of images and uh key value pairs basically like prompts and images prompts and images. So since it has been trained on millions of images, it now knows what you're trying to ask it. So you your the image is going to be

[3:51]Accurate as possible based on what your prompt is or how accurate your prompt is or your requirement is. Now let's see when I run this what the output comes. So like I said the stable here on the spaces it uses a GPU. It you have in your free trial you have a certain num uh GPU and request that you can do per day and it creates the image and also it has settings. You can set the width of the image, the height of the image, the guidance scales, the number of steps that you want it to iterate and go through your prompt before the image is

[4:34]Actually generated, the seed and etc. This is not the only model you can use to create images. There are multiple models out there. This is just an example on how you can use hugging face spaces to uh generate images. in this particular example. So if you can see this is like an really accurate image that has been created based on my prompt. Like I said I want strawberry jam. I said I want a human element. So a hand. I said I want strawberries. So there's strawberries presenting in croissants. And as well as if you can see the steam how accurate the steam is coming out of this coffee

[5:16]Coffee cup. So stable diffusions I believe and I consider it to be one of the best models present out there to create images. I think it is much accurate than daily can uh generate images. There's midjourney as well and we will have um models and we will have guides for it as well. So but this is about hugging face spaces and how you can use it. There's also a guide present for hugging space paces present under the appendex section. The use of hugging face spaces and what are the supported frameworks. It is gradu flask fast API how you can use hugging face spaces in this example. In this guide there are

[6:03]Two examples present. I've used a remove background model as well as the stable diffusion model. And the core components of a stable diffusion is the text to image generation. Like I said, you give a realistic prompt, you give an accurate prompt and it converts it into an image. You can also do an image to image transformation. Modify, enhance or style existing images based on prompts in painting. Restore files or replaces specific parts of a file while preserving its overall appearance and more. The advantages and the limitations of hugging face present are in present in the guide.

More videos

Humanitarians AI Lyrical Literacy Project