config.py 1023 B

123456789101112131415161718192021222324252627282930313233343536373839
  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. classification_model: str = "microsoft/resnet-50"
  8. clip_image_model: str = "ViT-B-32::openai"
  9. clip_text_model: str = "ViT-B-32::openai"
  10. facial_recognition_model: str = "buffalo_l"
  11. min_tag_score: float = 0.9
  12. eager_startup: bool = False
  13. model_ttl: int = 0
  14. host: str = "0.0.0.0"
  15. port: int = 3003
  16. workers: int = 1
  17. min_face_score: float = 0.7
  18. test_full: bool = False
  19. request_threads: int = os.cpu_count() or 4
  20. model_inter_op_threads: int = 1
  21. model_intra_op_threads: int = 2
  22. class Config:
  23. env_prefix = "MACHINE_LEARNING_"
  24. case_sensitive = False
  25. _clean_name = str.maketrans(":\\/", "___", ".")
  26. def get_cache_dir(model_name: str, model_type: ModelType) -> Path:
  27. return Path(settings.cache_folder) / model_type.value / model_name.translate(_clean_name)
  28. settings = Settings()