Hub Python Library documentation
管理您的 Space 运行时
管理您的 Space 运行时
请查阅 HfApi 文档页面,以获取用于在 Hub 上管理您的 Space 的方法参考。
- 获取当前运行时:get_space_runtime()
- 获取构建或运行日志:fetch_space_logs()
- 管理密钥:add_space_secret() 和 delete_space_secret()
- 管理硬件:request_space_hardware()
- 管理状态:pause_space()、restart_space()、set_space_sleep_time()
- 等待 Space 就绪:wait_for_space()
- 检查您的 ZeroGPU 配额:get_zero_gpu_quota()
数据结构
SpaceRuntime
类 huggingface_hub.SpaceRuntime
< source >( data: dict )
参数
- stage (
str) — 空间当前所处的阶段。示例:RUNNING。 - hardware (
str或None) — 当前 Space 的硬件。示例:“cpu-basic”。如果 Space 首次处于BUILDING状态,则可能为None。 - requested_hardware (
str或None) — 请求的硬件。如果请求刚刚提交,它可能与hardware不同。示例:“t4-medium”。如果尚未请求任何硬件,则可以为None。 - sleep_time (
int或None) — 在最后一次请求之后,Space 保持运行状态的秒数。默认情况下(如果值为None),当 Space 运行在升级后的硬件上时,它将永远不会进入休眠状态;而在免费的 ‘cpu-basic’ 硬件上,它将在 48 小时后进入休眠。更多详情,请参阅 https://huggingface.co/docs/hub/spaces-gpus#sleep-time。 - volumes (
list[Volume]或None) — 挂载在 Space 中的卷列表。每个卷都是一个 Volume 对象,描述其类型、源、挂载路径以及可选设置。如果没有附加任何卷,则为None。 - raw (
dict) — 来自服务器的原始响应。包含有关 Space 运行时的更多信息,例如副本数量、CPU 数量、内存大小等。
包含有关 Space 当前运行时的信息。
SpaceHardware
类 huggingface_hub.SpaceHardware
< source >( valuenames = Nonemodule = Nonequalname = Nonetype = Nonestart = 1 )
在 Hub 上运行您的 Space 时,可枚举的可用硬件列表。
SpaceStage
class huggingface_hub.SpaceStage
< source >( valuenames = Nonemodule = Nonequalname = Nonetype = Nonestart = 1 )
Hub 上 Space 可能处于的阶段枚举。
取自 https://github.com/huggingface/moon-landing/blob/main/server/repo_types/SpaceInfo.ts#L61(私有 URL)。
SpaceStorage
类 huggingface_hub.SpaceStorage
< source >( valuenames = Nonemodule = Nonequalname = Nonetype = Nonestart = 1 )
在 Hub 上为您的 Space 可用的持久存储列表。
取自 https://github.com/huggingface/moon-landing/blob/main/server/repo_types/SpaceHardwareFlavor.ts#L24(私有 URL)。
SpaceVariable
类 huggingface_hub.SpaceVariable
< source >( key: strvalues: dict )
包含有关 Space 当前变量的信息。
SpaceTemplate
class huggingface_hub.SpaceTemplate
< source >( data: dict )
包含有关 Hub 上可用 Space 模板的信息。
由 HfApi.list_space_templates() 返回。repo_id 可以作为 space_template 传递给 HfApi.create_repo(),以从该模板初始化一个新的 Space。
ZeroGpuQuota
类 huggingface_hub.ZeroGpuQuota
< source >( data: dict )
参数
- base (
float) — 总配额,以 GPU 秒为单位。 - remaining (
float) — 剩余配额,以 GPU 秒为单位。 - resets_at (
datetime或None) — 配额重置的日期。如果配额尚未使用,则为None。 - overquota_used (
float或None) — 基础配额用尽后消耗的超额(付费)GPU 秒数。PRO、Team 和 Enterprise 用户可以在 https://huggingface.co/settings/billing?add-credits=true 购买积分以超出基础配额。
包含有关已认证用户的 ZeroGPU 配额的详细信息。
每次使用 ZeroGPU Space(通过 UI 或其 API)时,都会消耗 ZeroGPU 配额,并且该配额会定期重置。有关更多详细信息,请参阅 https://huggingface.co/docs/hub/spaces-zerogpu。