| |
| import os |
| import torch |
| from pathlib import Path |
| from pydantic import Field |
| from typing import Optional |
| from pydantic_settings import BaseSettings |
|
|
|
|
| class Settings(BaseSettings): |
| """ |
| Main application settings |
| """ |
| |
| APP_NAME : str = "TEXT-AUTH" |
| APP_VERSION : str = "1.0.0" |
| APP_DESCRIPTION : str = "Text Authentication & Content Authenticity Platform" |
| |
| |
| ENVIRONMENT : str = Field(default = "development", env = "ENVIRONMENT") |
| DEBUG : bool = Field(default = True, env = "DEBUG") |
| |
| |
| HOST : str = Field(default = "0.0.0.0", env = "HOST") |
| PORT : int = Field(default = 8000, env = "PORT") |
| WORKERS : int = Field(default = 4, env = "WORKERS") |
| |
| |
| BASE_DIR : Path = Path(__file__).parent.parent.resolve() |
| MODEL_CACHE_DIR : Path = Field(default = Path(__file__).parent.parent / "models" / "cache", env = "MODEL_CACHE_DIR") |
| LOG_DIR : Path = Field(default = Path(__file__).parent.parent / "logs", env = "LOG_DIR") |
| UPLOAD_DIR : Path = Field(default = Path(__file__).parent.parent / "data" / "uploads", env = "UPLOAD_DIR") |
| REPORT_DIR : Path = Field(default = Path(__file__).parent.parent / "data" / "reports", env = "REPORT_DIR") |
| |
| |
| MAX_UPLOAD_SIZE : int = 10 * 1024 * 1024 |
| ALLOWED_EXTENSIONS : list = [".txt", ".pdf", ".docx", ".doc", ".md"] |
| |
| |
| MAX_TEXT_LENGTH : int = 500000 |
| MIN_TEXT_LENGTH : int = 200 |
| CHUNK_SIZE : int = 512 |
| CHUNK_OVERLAP : int = 50 |
| |
| |
| DEVICE : str = Field(default = "cpu", env = "DEVICE") |
| USE_QUANTIZATION : bool = Field(default = False, env = "USE_QUANTIZATION") |
| USE_ONNX : bool = Field(default = False, env = "USE_ONNX") |
| MODEL_LOAD_STRATEGY : str = "lazy" |
| MAX_CACHED_MODELS : int = 5 |
| |
| |
| AUTHENTICITY_CONFIDENCE_THRESHOLD : float = 0.7 |
| ENSEMBLE_METHOD : str = "weighted_average" |
| USE_DOMAIN_CALIBRATION : bool = True |
| |
| |
| RATE_LIMIT_ENABLED : bool = True |
| RATE_LIMIT_REQUESTS : int = 100 |
| RATE_LIMIT_WINDOW : int = 3600 |
| |
| |
| LOG_LEVEL : str = Field(default = "INFO", env = "LOG_LEVEL") |
| LOG_FORMAT : str = "%(asctime)s - %(name)s - %(levelname)s - %(message)s" |
| LOG_ROTATION : str = "1 day" |
| LOG_RETENTION : str = "30 days" |
| |
| |
| API_PREFIX : str = "/api/v1" |
| CORS_ORIGINS : list = ["*"] |
| |
| |
| DATABASE_URL : Optional[str] = Field(default = None, env = "DATABASE_URL") |
| |
| |
| SECRET_KEY : str = Field(default = "secret-key-change-in-production", env = "SECRET_KEY") |
| API_KEY_ENABLED : bool = False |
| |
| |
| ENABLE_HIGHLIGHTING : bool = True |
| ENABLE_PDF_REPORTS : bool = True |
| ENABLE_BATCH_PROCESSING : bool = True |
| |
| |
| MAX_CONCURRENT_REQUESTS : int = 10 |
| REQUEST_TIMEOUT : int = 300 |
| |
| |
| METRICS_ENABLED : dict = {"semantic_analysis" : True, |
| "multi_perturbation_stability" : True, |
| "perplexity" : True, |
| "structural" : True, |
| "entropy" : True, |
| "linguistic" : True, |
| } |
| |
| class Config: |
| env_file = ".env" |
| case_sensitive = True |
| extra = "ignore" |
|
|
| |
| def __init__(self, **kwargs): |
| super().__init__(**kwargs) |
| self._create_directories() |
| |
|
|
| def _create_directories(self): |
| """ |
| Create necessary directories if they don't exist |
| """ |
| for directory in [self.MODEL_CACHE_DIR, self.LOG_DIR, self.UPLOAD_DIR, self.REPORT_DIR]: |
| directory.mkdir(parents = True, exist_ok = True) |
| |
|
|
| @property |
| def is_production(self) -> bool: |
| """ |
| Check if running in production |
| """ |
| return self.ENVIRONMENT.lower() == "production" |
| |
|
|
| @property |
| def use_gpu(self) -> bool: |
| """ |
| Check if GPU is available and should be used |
| """ |
| return self.DEVICE == "cuda" and torch.cuda.is_available() |
|
|
|
|
|
|
| |
| settings = Settings() |
|
|
|
|
| |
| __all__ = ["settings", |
| "Settings", |
| ] |