2023-08-24 21:28:51 -07:00
|
|
|
import os
|
2023-06-24 20:18:09 -07:00
|
|
|
from pathlib import Path
|
|
|
|
|
2023-06-17 20:49:19 -07:00
|
|
|
from pydantic import BaseSettings
|
|
|
|
|
2023-06-24 20:18:09 -07:00
|
|
|
from .schemas import ModelType
|
|
|
|
|
|
|
|
|
2023-06-17 20:49:19 -07:00
|
|
|
class Settings(BaseSettings):
|
|
|
|
cache_folder: str = "/cache"
|
2023-08-20 16:24:14 -07:00
|
|
|
eager_startup: bool = False
|
2023-07-11 10:01:21 -07:00
|
|
|
model_ttl: int = 0
|
2023-06-17 20:49:19 -07:00
|
|
|
host: str = "0.0.0.0"
|
|
|
|
port: int = 3003
|
|
|
|
workers: int = 1
|
2023-06-27 16:21:33 -07:00
|
|
|
test_full: bool = False
|
2023-08-24 21:28:51 -07:00
|
|
|
request_threads: int = os.cpu_count() or 4
|
|
|
|
model_inter_op_threads: int = 1
|
|
|
|
model_intra_op_threads: int = 2
|
2023-06-17 20:49:19 -07:00
|
|
|
|
2023-08-05 19:45:13 -07:00
|
|
|
class Config:
|
2023-06-24 20:18:09 -07:00
|
|
|
env_prefix = "MACHINE_LEARNING_"
|
2023-06-17 20:49:19 -07:00
|
|
|
case_sensitive = False
|
|
|
|
|
|
|
|
|
2023-08-24 21:28:51 -07:00
|
|
|
_clean_name = str.maketrans(":\\/", "___", ".")
|
|
|
|
|
|
|
|
|
2023-06-24 20:18:09 -07:00
|
|
|
def get_cache_dir(model_name: str, model_type: ModelType) -> Path:
|
2023-08-24 21:28:51 -07:00
|
|
|
return Path(settings.cache_folder) / model_type.value / model_name.translate(_clean_name)
|
2023-06-24 20:18:09 -07:00
|
|
|
|
|
|
|
|
2023-06-17 20:49:19 -07:00
|
|
|
settings = Settings()
|