yangzhitao
refactor: enhance leaderboard functionality and improve code structure
d66a6a3
raw
history blame
2.09 kB
from functools import cached_property
from pathlib import Path
from typing import Annotated
from huggingface_hub import HfApi
from pydantic import Field, computed_field
from pydantic_settings import BaseSettings, SettingsConfigDict
# ----------------------------------
# Info to change for your repository
# ----------------------------------
class Settings(BaseSettings):
model_config = SettingsConfigDict(env_file=".env")
TOKEN: Annotated[str, Field(..., alias="HF_TOKEN", description="A read/write token for your org")]
# Change to your org - don't forget to create a results and request dataset, with the correct format!
OWNER: Annotated[
str,
Field("y-playground"),
]
@computed_field
@cached_property
def REPO_ID(self) -> str:
return (Path(self.OWNER) / "leaderboard").as_posix()
@computed_field
@cached_property
def QUEUE_REPO(self) -> str:
return (Path(self.OWNER) / "requests").as_posix()
@computed_field
@cached_property
def RESULTS_REPO(self) -> str:
return (Path(self.OWNER) / "results").as_posix()
CACHE_PATH: Annotated[
str,
Field(".", alias="HF_HOME", description="If you setup a cache later, just change `HF_HOME`"),
]
# Local caches
@computed_field
@cached_property
def EVAL_REQUESTS_PATH(self) -> str:
return (Path(self.CACHE_PATH) / "eval-queue").as_posix()
@computed_field
@cached_property
def EVAL_RESULTS_PATH(self) -> str:
return (Path(self.CACHE_PATH) / "eval-results").as_posix()
@computed_field
@cached_property
def EVAL_REQUESTS_PATH_BACKEND(self) -> str:
return (Path(self.CACHE_PATH) / "eval-queue-bk").as_posix()
@computed_field
@cached_property
def EVAL_RESULTS_PATH_BACKEND(self) -> str:
return (Path(self.CACHE_PATH) / "eval-results-bk").as_posix()
@computed_field
@cached_property
def API(self) -> HfApi:
return HfApi(token=self.TOKEN)
settings = Settings() # pyright: ignore[reportCallIssue]
API = settings.API