Spaces:
Paused
Paused
Download api/core/config.py from mrqadeer/email-classifier: direct link, hf CLI and curl.
- Browser
- Download file 1.54 kB
-
https://huggingface.co/spaces/mrqadeer/email-classifier/resolve/main/api/core/config.py
- Command line
-
hf download hf://spaces/mrqadeer/email-classifier/api/core/config.py
-
curl -L -o config.py https://huggingface.co/spaces/mrqadeer/email-classifier/resolve/main/api/core/config.py
1.54 kB
| from pydantic import AnyHttpUrl, validator | |
| from pydantic_settings import BaseSettings | |
| from typing import List, Optional, Union | |
| import os | |
| from dotenv import load_dotenv | |
| from pathlib import Path | |
| from email_spam_classifier.config import MODELS_DIR | |
| # Load .env file | |
| load_dotenv() | |
| class Settings(BaseSettings): | |
| # API settings | |
| API_PREFIX: str = "/api/v1" | |
| PROJECT_NAME: str = "Email Spam Classifier API" | |
| PROJECT_DESCRIPTION: str = "An API for classifying emails as spam or ham" | |
| PROJECT_VERSION: str = "1.0.0" | |
| # Server settings | |
| HOST: str = os.getenv("HOST", "0.0.0.0") | |
| PORT: int = int(os.getenv("PORT", 8000)) | |
| DEBUG: bool = os.getenv("DEBUG", "False").lower() in ("true", "1", "t") | |
| # Environment settings | |
| ENVIRONMENT: str = os.getenv("ENVIRONMENT", "development") | |
| # CORS settings | |
| CORS_ORIGINS: List[AnyHttpUrl] = [] | |
| # Model settings | |
| MODEL_PATH: Path = MODELS_DIR / "best_model.pkl" | |
| # Rate limiting | |
| RATE_LIMIT_ENABLED: bool = True | |
| RATE_LIMIT_REQUESTS: int = 100 | |
| RATE_LIMIT_TIMEFRAME: int = 3600 # seconds | |
| def assemble_cors_origins(cls, v: Union[str, List[str]]) -> Union[List[str], str]: | |
| if isinstance(v, str) and not v.startswith("["): | |
| return [i.strip() for i in v.split(",")] | |
| elif isinstance(v, (list, str)): | |
| return v | |
| raise ValueError(v) | |
| class Config: | |
| case_sensitive = True | |
| # Create settings instance | |
| settings = Settings() | |