File size: 1,899 Bytes
b4929ca
c85dcc4
b4929ca
 
 
c85dcc4
b4929ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c85dcc4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b4929ca
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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()