Download config.py from Atomio/facerecog: direct link, hf CLI and curl.
- Browser
- Download file 4.9 kB
-
https://huggingface.co/spaces/Atomio/facerecog/resolve/main/config.py
- Command line
-
hf download hf://spaces/Atomio/facerecog/config.py
-
curl -L -o config.py https://huggingface.co/spaces/Atomio/facerecog/resolve/main/config.py
4.9 kB
| """Global application configuration.""" | |
| from functools import lru_cache | |
| from typing import Any | |
| from pydantic import Field, PostgresDsn, field_validator | |
| from pydantic_settings import BaseSettings, SettingsConfigDict | |
| class Settings(BaseSettings): | |
| """Application settings.""" | |
| model_config = SettingsConfigDict( | |
| env_file=".env", | |
| env_file_encoding="utf-8", | |
| case_sensitive=True, | |
| extra="ignore", | |
| ) | |
| # Environment | |
| ENVIRONMENT: str = Field(default="local", description="Environment name") | |
| DEBUG: bool = Field(default=True, description="Debug mode") | |
| # FastAPI Configuration | |
| APP_NAME: str = Field(default="Face Recognition API", description="Application name") | |
| APP_VERSION: str = Field(default="0.1.0", description="Application version") | |
| HOST: str = Field(default="0.0.0.0", description="Host to bind") | |
| PORT: int = Field(default=8000, description="Port to bind") | |
| # Security | |
| SECRET_KEY: str = Field(description="Secret key for encryption") | |
| JWT_SECRET_KEY: str = Field(description="JWT secret key") | |
| JWT_ALGORITHM: str = Field(default="HS256", description="JWT algorithm") | |
| JWT_EXPIRE_MINUTES: int = Field(default=30, description="JWT expiration in minutes") | |
| # Supabase Configuration | |
| SUPABASE_URL: str = Field(description="Supabase project URL") | |
| SUPABASE_ANON_KEY: str = Field(description="Supabase anonymous key") | |
| SUPABASE_SERVICE_ROLE_KEY: str = Field(description="Supabase service role key") | |
| # Database Configuration (optional direct connection) | |
| DATABASE_URL: PostgresDsn | None = Field( | |
| default=None, description="Direct PostgreSQL connection URL" | |
| ) | |
| # CORS Configuration | |
| CORS_ORIGINS: list[str] = Field( | |
| default=["http://localhost:3000", "http://localhost:8080"], | |
| description="Allowed CORS origins", | |
| ) | |
| CORS_ALLOW_CREDENTIALS: bool = Field( | |
| default=True, description="Allow credentials in CORS" | |
| ) | |
| CORS_ALLOW_METHODS: list[str] = Field( | |
| default=["GET", "POST", "PUT", "DELETE", "OPTIONS"], | |
| description="Allowed CORS methods", | |
| ) | |
| CORS_ALLOW_HEADERS: list[str] = Field( | |
| default=["*"], description="Allowed CORS headers" | |
| ) | |
| # File Upload Configuration | |
| MAX_FILE_SIZE_MB: int = Field(default=50, description="Maximum file size in MB") | |
| UPLOAD_DIR: str = Field(default="uploads", description="Upload directory") | |
| TEMP_DIR: str = Field(default="temp", description="Temporary directory") | |
| # Logging Configuration | |
| LOG_LEVEL: str = Field(default="INFO", description="Logging level") | |
| LOG_FORMAT: str = Field(default="json", description="Logging format") | |
| # Redis Configuration (optional) | |
| REDIS_URL: str | None = Field(default=None, description="Redis connection URL") | |
| # Rate Limiting (optional) | |
| RATE_LIMIT_ENABLED: bool = Field(default=True, description="Enable rate limiting") | |
| RATE_LIMIT_REQUESTS_PER_MINUTE: int = Field( | |
| default=60, description="Rate limit requests per minute" | |
| ) | |
| # Monitoring (optional) | |
| SENTRY_DSN: str | None = Field(default=None, description="Sentry DSN for monitoring") | |
| # Development Tools | |
| SHOW_DOCS: bool = Field(default=True, description="Show API documentation") | |
| RELOAD: bool = Field(default=True, description="Enable auto-reload") | |
| def parse_cors_origins(cls, v: Any) -> list[str]: | |
| """Parse CORS origins from string or list.""" | |
| if isinstance(v, str): | |
| return [origin.strip() for origin in v.split(",")] | |
| return v | |
| def parse_cors_methods(cls, v: Any) -> list[str]: | |
| """Parse CORS methods from string or list.""" | |
| if isinstance(v, str): | |
| return [method.strip() for method in v.split(",")] | |
| return v | |
| def parse_cors_headers(cls, v: Any) -> list[str]: | |
| """Parse CORS headers from string or list.""" | |
| if isinstance(v, str): | |
| return [header.strip() for header in v.split(",")] | |
| return v | |
| def is_development(self) -> bool: | |
| """Check if running in development environment.""" | |
| return self.ENVIRONMENT.lower() in ("local", "development", "dev") | |
| def is_production(self) -> bool: | |
| """Check if running in production environment.""" | |
| return self.ENVIRONMENT.lower() in ("production", "prod") | |
| def max_file_size_bytes(self) -> int: | |
| """Get maximum file size in bytes.""" | |
| return self.MAX_FILE_SIZE_MB * 1024 * 1024 | |
| def get_settings() -> Settings: | |
| """Get cached application settings.""" | |
| return Settings() | |
| # Global settings instance | |
| settings = get_settings() | |