config.py 765 B

123456789101112131415161718192021222324252627282930313233
  1. import os
  2. from pathlib import Path
  3. from pydantic import BaseSettings
  4. from .schemas import ModelType
  5. class Settings(BaseSettings):
  6. cache_folder: str = "/cache"
  7. eager_startup: bool = False
  8. model_ttl: int = 0
  9. host: str = "0.0.0.0"
  10. port: int = 3003
  11. workers: int = 1
  12. test_full: bool = False
  13. request_threads: int = os.cpu_count() or 4
  14. model_inter_op_threads: int = 1
  15. model_intra_op_threads: int = 2
  16. class Config:
  17. env_prefix = "MACHINE_LEARNING_"
  18. case_sensitive = False
  19. _clean_name = str.maketrans(":\\/", "___", ".")
  20. def get_cache_dir(model_name: str, model_type: ModelType) -> Path:
  21. return Path(settings.cache_folder) / model_type.value / model_name.translate(_clean_name)
  22. settings = Settings()