Comprehensive toolkit for interacting with Hugging Face Spaces. Use this skill when working with Hugging Face Spaces - listing spaces, retrieving space information, managing space runtime (restart/pause), checking space status, or any other Space-related operations. Requires Hugging Face access token stored in HF_TOKEN or HUGGINGFACE_TOKEN environment variable for write operations.

0 stars
0 forks
Python
37 views

SKILL.md


name: hfskill description: Comprehensive toolkit for interacting with Hugging Face Spaces. Use this skill when working with Hugging Face Spaces - listing spaces, retrieving space information, managing space runtime (restart/pause), checking space status, or any other Space-related operations. Requires Hugging Face access token stored in HF_TOKEN or HUGGINGFACE_TOKEN environment variable for write operations.

Hugging Face Spaces Skill

Overview

This skill provides comprehensive operations for managing and interacting with Hugging Face Spaces. It enables listing, querying, and controlling Spaces through a Python-based interface that wraps the Hugging Face Hub API.

When to Use This Skill

Use this skill whenever working with Hugging Face Spaces, including:

  • Listing or searching for Spaces by author or keyword
  • Retrieving detailed information about a specific Space
  • Managing Space runtime (restart, pause)
  • Checking Space status and hardware configuration
  • Listing all Spaces owned by a user

Authentication Setup

Most Space operations require a Hugging Face access token. Configure authentication by:

  1. Environment Variable (Recommended): Set HF_TOKEN or HUGGINGFACE_TOKEN in the environment

    export HF_TOKEN="hf_your_token_here"
    
  2. Command-line Parameter: Pass --token to the script

    python3 scripts/space_operations.py --token "hf_your_token_here" <command>
    

Token Requirements:

  • Read operations (list, info, runtime): Token optional for public Spaces
  • Write operations (restart, pause): Token required with write permissions

Core Operations

1. List Spaces

List and search for Hugging Face Spaces with optional filtering.

Usage:

python3 scripts/space_operations.py list [--author USERNAME] [--search TERM] [--limit N]

Examples:

  • List recent Spaces: python3 scripts/space_operations.py list --limit 10
  • List Spaces by author: python3 scripts/space_operations.py list --author stabilityai
  • Search Spaces: python3 scripts/space_operations.py list --search "chatbot"

Output: JSON array of Space objects with id, author, SDK, likes, and runtime information.

2. Get Space Information

Retrieve detailed information about a specific Space.

Usage:

python3 scripts/space_operations.py info <space_id>

Example:

python3 scripts/space_operations.py info stabilityai/stable-diffusion

Output: JSON object with Space metadata including:

  • Space ID and author
  • SDK type and version
  • Runtime state and hardware
  • Privacy status and likes
  • Last modified timestamp

3. Restart Space

Restart a Space to apply changes or recover from errors.

Usage:

python3 scripts/space_operations.py restart <space_id>

Example:

python3 scripts/space_operations.py restart myusername/my-space

Requirements:

  • Valid access token with write permissions
  • Ownership or write access to the Space

4. Pause Space

Pause a Space to conserve compute resources when not in use.

Usage:

python3 scripts/space_operations.py pause <space_id>

Example:

python3 scripts/space_operations.py pause myusername/my-space

Requirements:

  • Valid access token with write permissions
  • Ownership or write access to the Space

5. Get Space Runtime

Retrieve real-time runtime information about a Space's current state.

Usage:

python3 scripts/space_operations.py runtime <space_id>

Example:

python3 scripts/space_operations.py runtime stabilityai/stable-diffusion

Output: JSON object with runtime details including stage, hardware, and sleep configuration.

6. List User Spaces

List all Spaces owned by a specific user.

Usage:

python3 scripts/space_operations.py user <username>

Example:

python3 scripts/space_operations.py user stabilityai

Output: JSON array of all Spaces for the specified user.

Space ID Format

All Spaces are identified using the format: username/space-name

Examples:

  • stabilityai/stable-diffusion
  • openai/whisper
  • meta-llama/llama-2-chat

Always use the full Space ID when referencing a specific Space.

Common Workflow Examples

Example 1: Find and Restart a Space

# List user's Spaces
python3 scripts/space_operations.py user myusername

# Check Space status
python3 scripts/space_operations.py runtime myusername/my-space

# Restart if needed
python3 scripts/space_operations.py restart myusername/my-space

Example 2: Search for Popular Spaces

# Search for chatbot Spaces
python3 scripts/space_operations.py list --search "chatbot" --limit 20

# Get detailed info about interesting Space
python3 scripts/space_operations.py info username/interesting-space

Example 3: Monitor Space Status

# Get current runtime information
python3 scripts/space_operations.py runtime myusername/my-space

# Get full Space details
python3 scripts/space_operations.py info myusername/my-space

Error Handling

Common errors and solutions:

  • "No HF_TOKEN found": Set the environment variable or pass --token
  • 401 Unauthorized: Invalid token or token expired
  • 403 Forbidden: Token lacks write permissions or you don't own the Space
  • 404 Not Found: Space doesn't exist or is private without proper access
  • 429 Too Many Requests: Rate limit exceeded, wait before retrying

Dependencies

This skill requires the huggingface_hub Python package:

pip install huggingface_hub

Verify installation before using the skill. If the package is missing, install it automatically or guide the user to install it.

Reference Documentation

For detailed information about Space states, hardware options, and API specifics, refer to references/spaces_reference.md.

Resources

scripts/

  • space_operations.py: Main executable script for all Space operations

references/

  • spaces_reference.md: Comprehensive reference documentation for Hugging Face Spaces API, runtime states, hardware options, and best practices

README

HFSkill - Hugging Face Spaces 管理工具包

一個全面的命令列工具包,用於管理和操作 Hugging Face Spaces。本工具提供了易於使用的操作功能,透過 Python 腳本來列出、監控和控制 Hugging Face Spaces。

功能特色

  • 列出 Spaces:依作者或關鍵字搜尋和過濾 Spaces
  • Space 資訊:取得任何 Space 的詳細元數據
  • 執行環境管理:重新啟動或暫停 Spaces
  • 狀態監控:檢查 Space 執行環境狀態和硬體配置
  • 使用者 Spaces:列出特定使用者擁有的所有 Spaces

安裝方式

  1. 複製此倉庫:
git clone https://github.com/joshhu/hfskill.git
cd hfskill
  1. 安裝相依套件:
pip install huggingface_hub

身份驗證

大多數操作需要 Hugging Face 存取權杖。使用以下其中一種方法配置身份驗證:

選項 1:環境變數(建議)

export HF_TOKEN="hf_your_token_here"

選項 2:命令列參數

python3 scripts/space_operations.py --token "hf_your_token_here" <command>

權杖需求:

  • 讀取操作:公開 Spaces 可選擇性提供權杖
  • 寫入操作(重新啟動/暫停):必須提供具有寫入權限的權杖

使用方法

列出 Spaces

# 列出最近的 Spaces
python3 scripts/space_operations.py list --limit 10

# 列出特定作者的 Spaces
python3 scripts/space_operations.py list --author stabilityai

# 搜尋 Spaces
python3 scripts/space_operations.py list --search "chatbot"

取得 Space 資訊

python3 scripts/space_operations.py info stabilityai/stable-diffusion

重新啟動 Space

python3 scripts/space_operations.py restart myusername/my-space

暫停 Space

python3 scripts/space_operations.py pause myusername/my-space

取得 Space 執行狀態

python3 scripts/space_operations.py runtime stabilityai/stable-diffusion

列出使用者的 Spaces

python3 scripts/space_operations.py user stabilityai

Space ID 格式

所有 Spaces 使用以下格式識別:username/space-name

範例:

  • stabilityai/stable-diffusion
  • openai/whisper
  • meta-llama/llama-2-chat

常用工作流程

監控並重新啟動 Space

# 檢查 Space 狀態
python3 scripts/space_operations.py runtime myusername/my-space

# 如有需要則重新啟動
python3 scripts/space_operations.py restart myusername/my-space

搜尋並探索 Spaces

# 搜尋聊天機器人 Spaces
python3 scripts/space_operations.py list --search "chatbot" --limit 20

# 取得詳細資訊
python3 scripts/space_operations.py info username/interesting-space

專案結構

hfskill/
├── SKILL.md                    # 詳細技能文件
├── README.md                   # 本檔案
├── scripts/
│   └── space_operations.py     # 主要執行腳本
└── references/
    └── spaces_reference.md     # API 參考文件

錯誤處理

常見錯誤及解決方案:

  • "No HF_TOKEN found":設定環境變數或傳入 --token
  • 401 Unauthorized:權杖無效或已過期
  • 403 Forbidden:權限不足或非 Space 擁有者
  • 404 Not Found:Space 不存在或為私有
  • 429 Too Many Requests:超過速率限制,請稍後重試

文件

有關 Space 狀態、硬體選項和 API 詳細資訊,請參閱:

  • SKILL.md - 完整技能文件
  • references/spaces_reference.md - API 參考

系統需求

  • Python 3.6+
  • huggingface_hub 套件

授權

MIT License

貢獻

歡迎貢獻!請隨時提交 Pull Request。