Spaces:
Sleeping
Sleeping
File size: 1,509 Bytes
6cc8ae1 | 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 59 60 61 62 | """
Application configuration using Pydantic Settings.
Reads from environment variables and .env file.
"""
import os
from pathlib import Path
from functools import lru_cache
from pydantic_settings import BaseSettings
class Settings(BaseSettings):
"""Application configuration from environment variables."""
# App
app_name: str = "Cattle Breed Classifier API"
app_version: str = "1.0.0"
debug: bool = False
# Model
model_path: str = os.environ.get(
"MODEL_PATH",
str(Path(__file__).resolve().parents[3] / "models" / "cattle_breed_classifier_full_model.pth")
)
model_name: str = os.environ.get("MODEL_NAME", "resnet")
model_version: str = os.environ.get("MODEL_VERSION", "v1.0")
# Metadata
metadata_path: str = os.environ.get(
"METADATA_PATH",
str(Path(__file__).resolve().parents[3] / "data" / "breed_metadata.csv")
)
classes_path: str = os.environ.get(
"CLASSES_PATH",
str(Path(__file__).resolve().parents[3] / "models" / "classes.txt")
)
# Image
image_size: int = 224
max_image_size_mb: float = 10.0
# Server
host: str = "0.0.0.0"
port: int = 8000
cors_origins: list[str] = ["*"]
# Inference
top_k: int = 3
url_timeout: int = 10
class Config:
env_file = ".env"
env_file_encoding = "utf-8"
case_sensitive = False
@lru_cache()
def get_settings() -> Settings:
"""Get cached settings instance."""
return Settings()
|