Spaces:
Running
Running
yangzhitao
feat: enhance leaderboard functionality and refactor app structure; update token handling and project metadata; update environment settings
c85dcc4
| from functools import cached_property | |
| from pathlib import Path | |
| from typing import Annotated | |
| from dotenv import load_dotenv | |
| from pydantic import Field, SecretStr, computed_field | |
| from pydantic_settings import BaseSettings, SettingsConfigDict | |
| load_dotenv() | |
| class Settings(BaseSettings): | |
| model_config = SettingsConfigDict(env_file=".env", extra="ignore") | |
| API_V1_STR: str = "/api/v1" | |
| # ------------------------------------------------------------ | |
| # Hugging Face settings | |
| # ------------------------------------------------------------ | |
| HF_TOKEN: Annotated[SecretStr, Field(description="Hugging Face Access Token")] = SecretStr("changethis") | |
| def hf_api(self): | |
| from huggingface_hub import HfApi | |
| token = self.HF_TOKEN.get_secret_value() | |
| if not token or token == "changethis": | |
| raise RuntimeError("Hugging Face Access Token is not set.") | |
| return HfApi( | |
| endpoint="https://huggingface.co", | |
| token=token, | |
| ) | |
| # Settings for Hugging Face repos | |
| HF_OWNER: str = "lmms-lab" | |
| HF_REPO_NAME: Annotated[str, Field(description="Name of leaderboard repo")] = "EASI-Leaderboard" | |
| HF_RESULTS_REPO_NAME: Annotated[str, Field(description="Name of results repo")] = "EASI-Leaderboard-Results" | |
| HF_REQUESTS_REPO_NAME: Annotated[str, Field(description="Name of requests repo")] = "EASI-Leaderboard-Requests" | |
| def REPO_ID(self) -> str: | |
| return (Path(self.HF_OWNER) / self.HF_REPO_NAME).as_posix() | |
| def RESULTS_REPO_ID(self) -> str: | |
| return (Path(self.HF_OWNER) / self.HF_RESULTS_REPO_NAME).as_posix() | |
| def QUEUE_REPO_ID(self) -> str: | |
| return (Path(self.HF_OWNER) / self.HF_REQUESTS_REPO_NAME).as_posix() | |
| settings = Settings() | |