Hub Python 庫文件

工作機會

Hugging Face's logo
加入 Hugging Face 社群

並獲得增強的文件體驗

開始使用

任務

請參閱 HfApi 文件頁面,瞭解管理 Hub 上任務的方法。

資料結構

JobInfo

class huggingface_hub.JobInfo

< >

( **kwargs )

引數

  • id (str) — 任務 ID。
  • created_at (datetime or None) — 任務建立時間。
  • docker_image (str or None) — 從 Docker Hub 拉取的用於該任務的 Docker 映象。如果存在 space_id,則可能為 None。
  • space_id (str or None) — 來自 Hugging Face Spaces 的用於該任務的 Docker 映象。如果存在 docker_image,則可能為 None。
  • command (list[str] or None) — 任務的命令,例如 ["python", "-c", "print('hello world')"]
  • arguments (list[str] or None) — 傳遞給命令的引數
  • environment (dict[str] or None) — 任務的環境變數,以字典形式表示。
  • secrets (dict[str] or None) — 任務的秘密環境變數(已加密)。
  • flavor (str or None) — 硬體的配置,如同 Hugging Face Spaces 中的一樣。有關可能值,請參閱 SpaceHardware。例如 "cpu-basic"
  • labels (dict[str, str] or None) — 要附加到任務的標籤(鍵值對)。
  • status — (JobStatus or None): 任務狀態,例如 JobStatus(stage="RUNNING", message=None)。有關可能的狀態值,請參閱 JobStage
  • owner — (JobOwner or None): 任務的所有者,例如 JobOwner(id="5e9ecfc04957053f60648a3e", name="lhoestq", type="user")

包含任務資訊。

示例

>>> from huggingface_hub import run_job
>>> job = run_job(
...     image="python:3.12",
...     command=["python", "-c", "print('Hello from the cloud!')"]
... )
>>> job
JobInfo(id='687fb701029421ae5549d998', created_at=datetime.datetime(2025, 7, 22, 16, 6, 25, 79000, tzinfo=datetime.timezone.utc), docker_image='python:3.12', space_id=None, command=['python', '-c', "print('Hello from the cloud!')"], arguments=[], environment={}, secrets={}, flavor='cpu-basic', labels=None, status=JobStatus(stage='RUNNING', message=None), owner=JobOwner(id='5e9ecfc04957053f60648a3e', name='lhoestq', type='user'), endpoint='https://huggingface.co', url='https://huggingface.co/jobs/lhoestq/687fb701029421ae5549d998')
>>> job.id
'687fb701029421ae5549d998'
>>> job.url
'https://huggingface.co/jobs/lhoestq/687fb701029421ae5549d998'
>>> job.status.stage
'RUNNING'

JobOwner

class huggingface_hub.JobOwner

< >

( id: str name: str type: str )

JobStage

class huggingface_hub.JobStage

< >

( value names = None module = None qualname = None type = None start = 1 )

Hub 上任務的可能階段的列舉。

值可以與字串進行比較

assert JobStage.COMPLETED == "COMPLETED"
可能的值為:`COMPLETED`、`CANCELED`、`ERROR`、`DELETED`、`RUNNING`。取自 https://github.com/huggingface/moon-landing/blob/main/server/job_types/JobInfo.ts#L61 (私有 URL)。

JobStatus

class huggingface_hub.JobStatus

< >

( stage: JobStage message: typing.Optional[str] )

在 GitHub 上更新

© . This site is unofficial and not affiliated with Hugging Face, Inc.