[CLI] Add hf spaces search command with semantic search#4094
Conversation
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]>
|
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. |
hanouticelina
left a comment
There was a problem hiding this comment.
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!
| query: str, | ||
| *, | ||
| filter: str | Iterable[str] | None = None, | ||
| sdk: str | list[str] | None = None, |
There was a problem hiding this comment.
| sdk: str | list[str] | None = None, | |
| sdk: str | None = None, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ 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, |
There was a problem hiding this comment.
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)
Reviewed by Cursor Bugbot for commit b7c430f. Configure here.
Co-authored-by: célina <[email protected]>
Co-authored-by: célina <[email protected]>
| Examples | ||
| $ hf spaces search "generate image" | ||
| $ hf spaces search "chatbot" --sdk gradio --limit 5 | ||
| $ hf spaces search "animate image" --description --json |
There was a problem hiding this comment.
since it is a semantic search, we can provide one example showing a longer sentence query, not just 2-3 keywords
There was a problem hiding this comment.
do you have a good example?
There was a problem hiding this comment.
remove background from photo
identify objects in pictures
There was a problem hiding this comment.
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"
}
]
|
could we release new version of cli so that I can have this change? 🙏 |
|
@mishig25 yes we'll do a release today! |
|
This PR has been shipped as part of the v1.11.0 release. |


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"hf spaces search "chatbot" --sdk gradio --limit 2hf spaces search "remove background from photo" --description --json --limit 1| jq🤖 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-searchresponse shape.Overview
Adds a new
HfApi.search_spacesmethod (and top-levelsearch_spaces) that calls the Hub’s/api/spaces/semantic-searchendpoint and returns structuredSpaceSearchResultobjects.Introduces a new
hf spaces searchCLI 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.