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") @cached_property 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" @computed_field @cached_property def REPO_ID(self) -> str: return (Path(self.HF_OWNER) / self.HF_REPO_NAME).as_posix() @computed_field @cached_property def RESULTS_REPO_ID(self) -> str: return (Path(self.HF_OWNER) / self.HF_RESULTS_REPO_NAME).as_posix() @computed_field @cached_property def QUEUE_REPO_ID(self) -> str: return (Path(self.HF_OWNER) / self.HF_REQUESTS_REPO_NAME).as_posix() settings = Settings()