Listing all your Spaces with ZeroGPU using powershell

Community Article Published April 8, 2025

Views Counter

In Hugging Face you can upload applications that use GPUs for free, using a resource called ZeroGPU (for those with a PRO account). This allows you to create apps that have access to powerful GPUs.
However, this is limited to only 10 spaces. Recently, when trying to create a new space with ZeroGPU, I encountered the limit error. But, through the interface, I saw that it is quite laborious to find spaces that have ZeroGPU, so I remembered that the Hugging Face API has a lot of information, and in PowershAI, it is very easy to use the API.

Through the interface, the closest way I found to do this is by going to the Spaces menu, where you have access to the trending spaces screen, and then filtering:

  1. Go to Spaces, top menu
  2. So, click on the filter icon
  3. Select ZeroGPU
  4. In the search field, type your username

While this method may work well for many cases, it has some drawbacks:

  • Note that, in the example above, it only listed 6 spaces. I needed to find 10 (because Hugging Face didn't let me create another Space with ZeroGPU due to reaching the limit). Private spaces were not listed, nor those containing errors.
  • The filter you use in the field is not exactly by author, so if another space has something with the same name as your user, it may be listed.

And this is where PowershAI comes in. With PowershAI, I can list all my spaces that use zero GPUs with a few simple commands.

If you have never installed powershell, follow the steps below to install and configure it to use Hugging Face. You only need to do this once. If you have already done so, you can skip the instructions below.

Installing Powershell and configuring Hugging Face for the first time

To install powershell, open a powershell and run the following command:

Install-Module -Scope CurrentUser powershai

If you receive an execution policy error, run this command:
Set-ExecutionPolicy -Scope Process Bypass

Now, you need a hugging face token. To generate it, it's very simple:

  1. Log in with your account in Hugging Face
  2. In the upper right corner, click on your avatar (a circle), a menu will open, and then go to "Access Tokens"
  3. So, look for a + Create Token button
  4. In Token Type, choose Read, give it a name (e.g., powershai) and click create
  5. Then, click the "Create token" button
  6. Keep the generated token, you will use it in the next step

Now that you have a hugging face token, just add it to powershell. The script below does that. It will ask you for the token:

# Import the module
import-module powershai

# Activate the Hugging Face provider
Set-AiProvider HuggingFace

# Enter your hugging face token
Set-AiCredential 

# Test the token
Get-HfMe # this command returns your user information

If you get errors, then it's probably a permission problem, incorrect step or even a powershell bug. If you reviewed and the error persists, contact me in the comments and I can help you (without exposing personal information or tokens)

Finally, so you don't have to do this whole process again, you can export the settings and protect them with a password. This password is used to generate keys to encrypt the tokens and save them to the computer where it is running. Use a secure and easy-to-remember password:

# powershai never transmit this password over the internet or save it
Export-PowershellSettings

# When you want to import again, just use
Import-PowershellSettings # and enter the password used

Getting ZeroGPU info

Once you have your powershell ready to chat with Hugging Face, let's go to the commands:

Get-HfSpace -My | %{ Get-HfSpace $_.id -NoGradioSession } | ?{ $_.runtime.hardware.requested -like 'zero-*' } | select id,private

Let's explain each of the commands separated by the pipe, starting from the left:

  • Get-HfSpace -My
    This command returns all your spaces. However, it only returns some basic information, such as the space id.

  • %{ Get-HfSpace $_.id -NoGradioSession }
    In powershell, % is an alias for the foreach-object command, which simply repeats the command between the braces for each result of the previous command and allows access to that result with the variable $_. In other words, we are running Get-HfSpace again, but passing the ID of each space. With this, the command returns much more detail. I opened an Issue to improve this and bring this info with only one call Get-HfSpace -My
    The parameter -NoGradioSession prevents powershell from trying to open a connection with Gradio, which would slow down execution. This is not necessary since we don't want to interact with the Space, but only obtain metadata from it.

  • ?{ $_.runtime.hardware.requested -like ‘zero-*’ }
    ? is an alias for Where-Object, which is a command that filters the result.
    In this case, we are accessing the runtime.hardware property of each of the spaces.
    In this object we will have another property, called requested, which indicates the requested hardware. In observations, I noticed that ZeroGPU always starts with zero-

  • select id,private
    Finally, using the select command (which is an alias of Select-Object) to bring only the id and private properties, indicating whether the space is private or not.

Running the command above with my user, it returned the following

If you want, you can save the complete result in a variable and explore it further later:

$spaces = Get-HfSpace -My | %{ Get-HfSpace $_.id -NoGradioSession } | ?{ $_.runtime.hardware.requested -like 'zero-*' }

PowershAI is an incredible module and this integration with Hugging Face has many sensational features for those who need to obtain information and interact with Hugging Face! This link contains a basic doc how to use Hugging Face with powershell

If you want to know more about the project, suggest features, corrections, etc., check it out on git:rrg92/powershai: PowerShell + AI

Community

Your need to confirm your account before you can post a new comment.

Sign up or log in to comment