lukhsaankumar's picture
Deploy DeepFake Detector API - 2026-04-21 00:22:37
7bd3f6d
Raw History Blame Contribute Delete
2.44 kB
"""
Application configuration with environment variable support.
"""
import os
from functools import lru_cache
from pydantic_settings import BaseSettings
from typing import Optional
def _default_hf_cache_dir() -> str:
"""Prefer persistent storage on HF Spaces when available."""
if os.path.isdir("/data"):
return "/data/.hf_cache"
return "/app/.hf_cache"
def _default_hf_home() -> str:
"""Prefer persistent Hugging Face home on HF Spaces when available."""
if os.path.isdir("/data"):
return "/data/.cache/huggingface"
return "/app/.hf_cache/hf_home"
class Settings(BaseSettings):
"""Application settings loaded from environment variables."""
# Hugging Face configuration
# Available fusion models:
# - DeepFakeDetector/fusion-logreg-final (Logistic Regression - default)
# - DeepFakeDetector/fusion-meta-final (Meta-classifier)
HF_FUSION_REPO_ID: str = "DeepFakeDetector/fusion-logreg-final"
HF_CACHE_DIR: str = _default_hf_cache_dir()
HF_HOME: str = _default_hf_home()
HF_PERSISTENT_CACHE: bool = True
HF_PERSISTENT_CACHE_ROOT: str = "/data"
HF_TOKEN: Optional[str] = None
# Google Gemini API configuration
GOOGLE_API_KEY: Optional[str] = None
GEMINI_MODEL: str = "gemini-2.5-flash"
@property
def llm_enabled(self) -> bool:
"""Check if LLM explanations are available."""
return self.GOOGLE_API_KEY is not None and len(self.GOOGLE_API_KEY) > 0
# Application configuration
ENABLE_DEBUG: bool = False
LOG_LEVEL: str = "INFO"
# Server configuration
HOST: str = "0.0.0.0"
PORT: int = 8000
# CORS configuration
CORS_ORIGINS: str = "http://localhost:5173,http://localhost:3000,https://www.deepfake-detector.app,https://deepfake-detector.app"
@property
def cors_origins_list(self) -> list[str]:
"""Parse CORS origins from comma-separated string."""
return [origin.strip() for origin in self.CORS_ORIGINS.split(",") if origin.strip()]
# API configuration
API_V1_PREFIX: str = "/api/v1"
PROJECT_NAME: str = "DeepFake Detector API"
VERSION: str = "0.1.0"
class Config:
env_file = ".env"
env_file_encoding = "utf-8"
case_sensitive = True
@lru_cache()
def get_settings() -> Settings:
"""Get cached settings instance."""
return Settings()
settings = get_settings()