Skip to content

[CLI] Add hf spaces search command with semantic search#4094

Merged
Wauplin merged 9 commits intomainfrom
add-space-semantic-search
Apr 15, 2026
Merged

[CLI] Add hf spaces search command with semantic search#4094
Wauplin merged 9 commits intomainfrom
add-space-semantic-search

Conversation

@Wauplin
Copy link
Copy Markdown
Contributor

@Wauplin Wauplin commented Apr 13, 2026

This PR introduces search_spaces() to perform semantic search of Spaces on the Hub (this endpoint: https://huggingface.co/api/spaces/semantic-search?q=generate+image)

Also adds hf spaces search <query> CLI command.

hf spaces search "generate image"

ID                                  TITLE                       SDK    LIKES STAGE   CATEGORY         SCORE
----------------------------------- --------------------------- ------ ----- ------- ---------------- -----
mrfakename/Z-Image-Turbo            Z Image Turbo               gradio 2867  RUNNING Image Generation 0.9  
r3gm/wan2-2-fp8da-aoti-preview      Wan2.2 14B Preview          gradio 2016  RUNNING Video Generation 0.81 
black-forest-labs/FLUX.2-dev        FLUX.2 [dev]                gradio 825   RUNNING Image Generation 0.77 
black-forest-labs/FLUX.2-klein-9B   FLUX.2 [Klein] 9B           gradio 739   RUNNING Image Generation 0.76 
Kwai-Kolors/Kolors-Virtual-Try-On   Kolors Virtual Try-On       gradio 10028 RUNNING Image Editing    0.75 
multimodalart/nano-banana           Nano Banana PRO             gradio 663   RUNNING Image Generation 0.75 
microsoft/TRELLIS.2                 TRELLIS.2                   gradio 1394  RUNNING 3D Modeling      0.74 
black-forest-labs/FLUX.1-dev        FLUX.1 [dev]                gradio 9427  RUNNING Image Generation 0.74 
r3gm/wan2-2-fp8da-aoti-preview2     Wan2.2 14B Fast Preview     gradio 667   RUNNING Video Generation 0.74 
prithivMLmods/FireRed-Image-Edit... FireRed Image Edit 1.0 Fast gradio 803   RUNNING Image Editing    0.73 
Hint: Use --description to show AI-generated descriptions.

hf spaces search "chatbot" --sdk gradio --limit 2

ID                      TITLE   SDK    LIKES STAGE   CATEGORY SCORE
----------------------- ------- ------ ----- ------- -------- -----
BarBar288/Chatbot       Chatbot gradio 4     RUNNING Other    0.5  
Pankajpandey221/Chatbot Chatbot gradio 2     RUNNING Chatbots 0.47 
Hint: Use --description to show AI-generated descriptions.

hf spaces search "remove background from photo" --description --json --limit 1| jq

[
  {
    "id": "briaai/BRIA-RMBG-1.4",
    "title": "BRIA RMBG 1.4",
    "sdk": "gradio",
    "likes": 871,
    "stage": "RUNNING",
    "category": "Image Editing",
    "score": 0.87,
    "description": "Remove background from your photos instantly"
  }
]

🤖 Generated with Claude Code


Note

Low Risk
Additive API/CLI and documentation changes with minimal impact on existing behavior; main risk is correctness/compatibility with the new /api/spaces/semantic-search response shape.

Overview
Adds a new HfApi.search_spaces method (and top-level search_spaces) that calls the Hub’s /api/spaces/semantic-search endpoint and returns structured SpaceSearchResult objects.

Introduces a new hf spaces search CLI command that renders search results (optionally including AI-generated descriptions) and updates docs/API reference to document the new search capability, with a basic test covering the new API.

Reviewed by Cursor Bugbot for commit 7f23ec9. Bugbot is set up for automated code reviews on this repo. Configure here.

Add `search_spaces()` method to `HfApi` and `hf spaces search <query>` CLI command
that calls the Hub's semantic search API (`/api/spaces/semantic-search`).

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@bot-ci-comment
Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@Wauplin Wauplin marked this pull request as ready for review April 13, 2026 14:07
Copy link
Copy Markdown
Contributor

@hanouticelina hanouticelina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks! i left a comment about the missing exports (search_spaces = api.search_spaces in hf_api.py + __init__.py) otherwise looks good to me!

Comment thread src/huggingface_hub/hf_api.py
Comment thread src/huggingface_hub/_space_api.py Outdated
query: str,
*,
filter: str | Iterable[str] | None = None,
sdk: str | list[str] | None = None,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sdk: str | list[str] | None = None,
sdk: str | None = None,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated in b7c430f to allow multiple sdks in CLI (instead of forbidding it in API).

Tested and works as expected:

✗ hf spaces search "image generation" --sdk static
ID                         TITLE                               SDK    LIKES STAGE   CATEGORY      SCORE
-------------------------- ----------------------------------- ------ ----- ------- ------------- -----
ArtelTaleb/8view-ai-studio 8view AI — 3D Topology Reference... static 5     RUNNING 3D Modeling   0.8  
byliang/SECA               SECA: Semantically Equivalent an... static 3     RUNNING Text Analysis 0.04 
Hint: Use --description to show AI-generated descriptions.

✗ hf spaces search "image generation" --sdk docker
ID                            TITLE                 SDK    LIKES STAGE   CATEGORY         SCORE
----------------------------- --------------------- ------ ----- ------- ---------------- -----
gdTharusha/3D-Modle-Generator TripoSR               docker 51    RUNNING 3D Modeling      0.85 
jbilcke-hf/ai-comic-factory   AI Comic Factory      docker 11024 RUNNING Image Generation 0.73 
lsmpp/openpose                OpenPose Preprocessor docker 6     RUNNING Image Processing 0.63 
lokesh180340026/Comfy-UI      Comfy UI              docker 5     RUNNING Image Generation 0.22 
Hint: Use --description to show AI-generated descriptions.

✗ hf spaces search "image generation" --sdk docker --sdk static
ID                            TITLE                               SDK    LIKES STAGE   CATEGORY         SCORE
----------------------------- ----------------------------------- ------ ----- ------- ---------------- -----
gdTharusha/3D-Modle-Generator TripoSR                             docker 51    RUNNING 3D Modeling      0.85 
lokesh180340026/Comfy-UI      Comfy UI                            docker 5     RUNNING Image Generation 0.79 
jbilcke-hf/ai-comic-factory   AI Comic Factory                    docker 11024 RUNNING Image Generation 0.77 
lsmpp/openpose                OpenPose Preprocessor               docker 6     RUNNING Image Processing 0.66 
ArtelTaleb/8view-ai-studio    8view AI — 3D Topology Reference... static 5     RUNNING 3D Modeling      0.66 
byliang/SECA                  SECA: Semantically Equivalent an... static 3     RUNNING Text Analysis    0.04 
Hint: Use --description to show AI-generated descriptions.

@Wauplin Wauplin requested a review from hanouticelina April 13, 2026 20:07
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit b7c430f. Configure here.

def spaces_search(
query: Annotated[str, typer.Argument(help="Search query.")],
filter: FilterOpt = None,
sdk: Annotated[list[str] | None, typer.Option(help="Filter by SDK (e.g. gradio, docker, static).")] = None,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CLI sdk parameter type allows unsupported multi-value input

Low Severity

The CLI declares sdk as list[str] | None, allowing users to pass multiple --sdk values (e.g. --sdk gradio --sdk docker). The API method also accepts list[str]. However, the semantic search endpoint documentation and CLI help text ("Filter by SDK (e.g. gradio, docker, static).") imply a single value. This was also flagged by a reviewer suggesting sdk: str | None. Passing multiple SDK values may produce unexpected server behavior or silently drop values.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit b7c430f. Configure here.

Copy link
Copy Markdown
Contributor

@hanouticelina hanouticelina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Comment thread docs/source/en/guides/manage-spaces.md Outdated
Comment thread docs/source/en/guides/manage-spaces.md Outdated
Comment thread docs/source/en/package_reference/cli.md
Comment thread docs/source/en/package_reference/cli.md Outdated
Comment on lines +3539 to +3542
Examples
$ hf spaces search "generate image"
$ hf spaces search "chatbot" --sdk gradio --limit 5
$ hf spaces search "animate image" --description --json
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since it is a semantic search, we can provide one example showing a longer sentence query, not just 2-3 keywords

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you have a good example?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove background from photo

identify objects in pictures

Copy link
Copy Markdown
Contributor Author

@Wauplin Wauplin Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks

added them in examples:

(huggingface_hub) ➜  huggingface_hub git:(add-space-semantic-search) ✗ hf spaces search "identify objects in pictures" --sdk gradio --limit 5
ID                                  TITLE                       SDK    LIKES STAGE   CATEGORY         SCORE
----------------------------------- --------------------------- ------ ----- ------- ---------------- -----
mrfakename/Z-Image-Turbo            Z Image Turbo               gradio 2874  RUNNING Image Generation 0.77 
prithivMLmods/FireRed-Image-Edit... FireRed Image Edit 1.0 Fast gradio 810   RUNNING Image Editing    0.73 
prithivMLmods/SAM3-Plus-Qwen3.5     SAM3 + Qwen3.5              gradio 13    RUNNING Object Detection 0.7  
allenai/WildDet3D                   AI2 - WildDet3D             gradio 14    RUNNING Object Detection 0.69 
black-forest-labs/FLUX.2-klein-9B   FLUX.2 [Klein] 9B           gradio 742   RUNNING Image Generation 0.68 
Hint: Use --description to show AI-generated descriptions.

(huggingface_hub) ➜  huggingface_hub git:(add-space-semantic-search) ✗ hf spaces search "remove background from photo" --description --json  --limit 1| jq 
[
  {
    "id": "briaai/BRIA-RMBG-1.4",
    "title": "BRIA RMBG 1.4",
    "sdk": "gradio",
    "likes": 871,
    "stage": "RUNNING",
    "category": "Image Editing",
    "score": 0.87,
    "description": "Remove background from your photos instantly"
  }
]

@Wauplin Wauplin merged commit b3a8eb5 into main Apr 15, 2026
17 of 21 checks passed
@Wauplin Wauplin deleted the add-space-semantic-search branch April 15, 2026 11:45
@Wauplin Wauplin added the highlight PR will be highlighted in the release notes. label Apr 15, 2026
@mishig25
Copy link
Copy Markdown
Contributor

could we release new version of cli so that I can have this change? 🙏

@hanouticelina
Copy link
Copy Markdown
Contributor

@mishig25 yes we'll do a release today!

@huggingface-hub-bot
Copy link
Copy Markdown
Contributor

This PR has been shipped as part of the v1.11.0 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

highlight PR will be highlighted in the release notes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants