Voice et bot modif

This commit is contained in:
pi 2026-06-16 17:09:34 +00:00
parent 189d56026b
commit 7333a22bcd
10774 changed files with 634644 additions and 933308 deletions

View file

@ -1,4 +1,3 @@
# coding=utf-8
# Copyright 2019-present, the HuggingFace Inc. team.
#
# Licensed under the Apache License, Version 2.0 (the "License");
@ -15,9 +14,9 @@
from dataclasses import dataclass
from datetime import datetime
from enum import Enum
from typing import Optional
from typing import Literal
from huggingface_hub.utils import parse_datetime
from huggingface_hub.utils import HfMount, HfUri, parse_datetime
class SpaceStage(str, Enum):
@ -43,6 +42,8 @@ class SpaceStage(str, Enum):
DELETING = "DELETING"
STOPPED = "STOPPED"
PAUSED = "PAUSED"
APP_STARTING = "APP_STARTING"
RUNNING_APP_STARTING = "RUNNING_APP_STARTING"
class SpaceHardware(str, Enum):
@ -60,7 +61,6 @@ class SpaceHardware(str, Enum):
# CPU
CPU_BASIC = "cpu-basic"
CPU_UPGRADE = "cpu-upgrade"
CPU_XL = "cpu-xl"
# ZeroGPU
ZERO_A10G = "zero-a10g"
@ -78,8 +78,8 @@ class SpaceHardware(str, Enum):
A10G_LARGEX2 = "a10g-largex2"
A10G_LARGEX4 = "a10g-largex4"
A100_LARGE = "a100-large"
H100 = "h100"
H100X8 = "h100x8"
A100X4 = "a100x4"
A100X8 = "a100x8"
class SpaceStorage(str, Enum):
@ -99,6 +99,79 @@ class SpaceStorage(str, Enum):
LARGE = "large"
@dataclass
class Volume:
"""
Describes a volume to mount in a Space or Job container.
Args:
type (`str`):
Type of volume: `"bucket"`, `"model"`, `"dataset"`, or `"space"`.
source (`str`):
Source identifier, e.g. `"username/my-bucket"` or `"username/my-model"`.
mount_path (`str`):
Mount path inside the container, e.g. `"/data"`. Must start with `/`.
revision (`str` or `None`):
Git revision (only for repos, defaults to `"main"`).
read_only (`bool` or `None`):
Read-only mount. Forced `True` for repos, defaults to `False` for buckets.
path (`str` or `None`):
Subfolder prefix inside the bucket/repo to mount, e.g. `"path/to/dir"`.
"""
type: Literal["bucket", "model", "dataset", "space"]
source: str
mount_path: str
revision: str | None = None
read_only: bool | None = None
path: str | None = None
def __init__(self, **kwargs) -> None:
self.type = kwargs.get("type", "model")
self.source = kwargs["source"]
mount_path = kwargs.get("mountPath")
self.mount_path = mount_path if mount_path is not None else kwargs["mount_path"]
self.revision = kwargs.get("revision")
read_only = kwargs.get("readOnly")
self.read_only = read_only if read_only is not None else kwargs.get("read_only")
self.path = kwargs.get("path")
def to_dict(self) -> dict:
"""Serialize to the JSON payload expected by the Hub API."""
data: dict = {
"type": self.type,
"source": self.source,
"mountPath": self.mount_path,
}
if self.revision is not None:
data["revision"] = self.revision
if self.read_only is not None:
data["readOnly"] = self.read_only
if self.path is not None:
data["path"] = self.path
return data
def to_uri(self) -> str:
"""Return the volume as an HF mount URI in the format expected by the CLI."""
return HfMount(
source=HfUri(type=self.type, id=self.source, revision=self.revision, path_in_repo=self.path or ""),
mount_path=self.mount_path,
read_only=self.read_only,
).to_uri()
@dataclass
class SpaceHotReloading:
status: Literal["created", "canceled"]
replica_statuses: list[tuple[str, str | None]] # See _hot_reloading_types.ApiCreateReloadResponse.res.status
raw: dict
def __init__(self, data: dict) -> None:
self.status = data["status"]
self.replica_statuses = data["replicaStatuses"]
self.raw = data
@dataclass
class SpaceRuntime:
"""
@ -118,16 +191,22 @@ class SpaceRuntime:
Number of seconds the Space will be kept alive after the last request. By default (if value is `None`), the
Space will never go to sleep if it's running on an upgraded hardware, while it will go to sleep after 48
hours on a free 'cpu-basic' hardware. For more details, see https://huggingface.co/docs/hub/spaces-gpus#sleep-time.
volumes (`list[Volume]` or `None`):
List of volumes mounted in the Space. Each volume is a [`Volume`] object describing its type, source,
mount path, and optional settings. `None` if no volumes are attached.
raw (`dict`):
Raw response from the server. Contains more information about the Space
runtime like number of replicas, number of cpu, memory size,...
"""
stage: SpaceStage
hardware: Optional[SpaceHardware]
requested_hardware: Optional[SpaceHardware]
sleep_time: Optional[int]
storage: Optional[SpaceStorage]
hardware: SpaceHardware | None
requested_hardware: SpaceHardware | None
sleep_time: int | None
storage: SpaceStorage | None
dev_mode: bool
hot_reloading: SpaceHotReloading | None
volumes: list[Volume] | None
raw: dict
def __init__(self, data: dict) -> None:
@ -136,9 +215,41 @@ class SpaceRuntime:
self.requested_hardware = data.get("hardware", {}).get("requested")
self.sleep_time = data.get("gcTimeout")
self.storage = data.get("storage")
self.dev_mode = data.get("devMode", False)
self.hot_reloading = SpaceHotReloading(raw_hr) if (raw_hr := data.get("hotReloading")) is not None else None
raw_volumes = data.get("volumes")
self.volumes = [Volume(**v) for v in raw_volumes] if raw_volumes is not None else None
self.raw = data
@dataclass
class SpaceSecret:
"""
Contains information about a secret of a Space.
Secret values are write-only and cannot be read back. Only the key, description,
and last update time are returned by the API.
Args:
key (`str`):
Secret key. Example: `"GITHUB_API_KEY"`
description (`str` or None):
Description of the secret. Example: `"Github API key to access the Github API"`.
updated_at (`datetime` or None):
datetime of the last update of the secret (if the secret has been updated at least once).
"""
key: str
description: str | None
updated_at: datetime | None
def __init__(self, key: str, values: dict) -> None:
self.key = key
self.description = values.get("description")
updated_at = values.get("updatedAt")
self.updated_at = parse_datetime(updated_at) if updated_at is not None else None
@dataclass
class SpaceVariable:
"""
@ -157,8 +268,8 @@ class SpaceVariable:
key: str
value: str
description: Optional[str]
updated_at: Optional[datetime]
description: str | None
updated_at: datetime | None
def __init__(self, key: str, values: dict) -> None:
self.key = key
@ -166,3 +277,69 @@ class SpaceVariable:
self.description = values.get("description")
updated_at = values.get("updatedAt")
self.updated_at = parse_datetime(updated_at) if updated_at is not None else None
@dataclass
class SpaceSearchResult:
"""A single result from the Spaces semantic search API.
Returned by [`HfApi.search_spaces`].
Attributes:
id (`str`):
ID of the Space (e.g. `"username/repo-name"`).
author (`str`):
Author of the Space.
title (`str`):
Display title of the Space.
emoji (`str` or `None`):
Emoji icon of the Space.
sdk (`str` or `None`):
SDK used by the Space (e.g. `"gradio"`, `"docker"`, `"static"`).
likes (`int`):
Number of likes.
private (`bool`):
Whether the Space is private.
tags (`list[str]` or `None`):
List of tags.
runtime ([`SpaceRuntime`] or `None`):
Runtime information (stage, hardware, etc.).
ai_short_description (`str` or `None`):
AI-generated short description.
ai_category (`str` or `None`):
AI-generated category (e.g. `"Image Generation"`).
semantic_relevancy_score (`float` or `None`):
Semantic relevancy score (0-1) relative to the search query.
trending_score (`int` or `None`):
Trending score.
"""
id: str
author: str
title: str
emoji: str | None
sdk: str | None
likes: int
private: bool
tags: list[str] | None
runtime: SpaceRuntime | None
ai_short_description: str | None
ai_category: str | None
semantic_relevancy_score: float | None
trending_score: int | None
def __init__(self, data: dict) -> None:
runtime = data.get("runtime")
self.id = data["id"]
self.author = data.get("author", "")
self.title = data.get("title", "")
self.emoji = data.get("emoji")
self.sdk = data.get("sdk")
self.likes = data.get("likes", 0)
self.private = data.get("private", False)
self.tags = data.get("tags")
self.runtime = SpaceRuntime(runtime) if runtime else None
self.ai_short_description = data.get("ai_short_description")
self.ai_category = data.get("ai_category")
self.semantic_relevancy_score = data.get("semanticRelevancyScore")
self.trending_score = data.get("trendingScore")