FaceMatch-Azure-Dev / config.py
ashutosh-koottu's picture
Debugging to check embeddings path
e5cf5e6
import os
from typing import Dict, Any
class Config:
"""Configuration class for FaceMatch application"""
# Azure Storage Configuration
AZURE_STORAGE_CONNECTION_STRING = os.getenv('AZURE_STORAGE_CONNECTION_STRING', '')
AZURE_STORAGE_ACCOUNT_NAME = os.getenv('AZURE_STORAGE_ACCOUNT_NAME', '')
AZURE_STORAGE_ACCOUNT_KEY = os.getenv('AZURE_STORAGE_ACCOUNT_KEY', '')
AZURE_CONTAINER_NAME = os.getenv('AZURE_CONTAINER_NAME', 'koottu-media')
AZURE_PREFIX = os.getenv('AZURE_PREFIX', 'koottu-media/profile-media/')
AZURE_EMBEDDINGS_FOLDER = os.getenv('AZURE_EMBEDDINGS_FOLDER', 'koottu-media/embeddings/')
AZURE_TRAINING_IMAGES_FOLDER = os.getenv('AZURE_TRAINING_IMAGES_FOLDER', 'koottu-media/ai-images/')
# Face Recognition Configuration
INSIGHTFACE_CTX_ID = int(os.getenv('INSIGHTFACE_CTX_ID', '0')) # 0 for GPU, -1 for CPU
FACE_EMBEDDING_DIMENSION = 512
SIMILARITY_THRESHOLD = float(os.getenv('SIMILARITY_THRESHOLD', '0.5'))
# Application Configuration
FLASK_SECRET_KEY = os.getenv('FLASK_SECRET_KEY', 'your-secret-key-here')
FLASK_HOST = os.getenv('FLASK_HOST', '0.0.0.0')
FLASK_PORT = int(os.getenv('FLASK_PORT', '5000'))
FLASK_DEBUG = os.getenv('FLASK_DEBUG', 'True').lower() == 'true'
# User Preferences Configuration
USER_PREFERENCES_FILE = os.getenv('USER_PREFERENCES_FILE', 'user_preferences.json')
MAX_TRAINING_IMAGES = int(os.getenv('MAX_TRAINING_IMAGES', '10'))
DEFAULT_MATCH_COUNT = int(os.getenv('DEFAULT_MATCH_COUNT', '10'))
MAX_MATCH_COUNT = int(os.getenv('MAX_MATCH_COUNT', '50'))
# Embedding Database Configuration
EMBEDDING_UPDATE_DAYS = int(os.getenv('EMBEDDING_UPDATE_DAYS', '30'))
MIN_FACE_CONFIDENCE = float(os.getenv('MIN_FACE_CONFIDENCE', '0.5'))
# Performance Configuration
BATCH_SIZE = int(os.getenv('BATCH_SIZE', '10'))
CACHE_TTL = int(os.getenv('CACHE_TTL', '3600')) # 1 hour
@classmethod
def get_azure_config(cls) -> Dict[str, Any]:
"""Get Azure Storage configuration dictionary"""
config = {
'connection_string': cls.AZURE_STORAGE_CONNECTION_STRING,
'account_name': cls.AZURE_STORAGE_ACCOUNT_NAME,
'account_key': cls.AZURE_STORAGE_ACCOUNT_KEY,
'container_name': cls.AZURE_CONTAINER_NAME
}
print("\n" + "="*80)
print("AZURE CONFIGURATION DEBUG")
print("="*80)
print(f"Account Name: {cls.AZURE_STORAGE_ACCOUNT_NAME or '(NOT SET)'}")
print(f"Container: {cls.AZURE_CONTAINER_NAME}")
print(f"Connection String: {'SET' if cls.AZURE_STORAGE_CONNECTION_STRING else '(NOT SET)'}")
print(f"Account Key: {'SET' if cls.AZURE_STORAGE_ACCOUNT_KEY else '(NOT SET)'}")
print("="*80 + "\n")
return config
@classmethod
def get_storage_config(cls) -> Dict[str, str]:
"""Get storage configuration dictionary"""
return {
'container_name': cls.AZURE_CONTAINER_NAME,
'prefix': cls.AZURE_PREFIX,
'embeddings_folder': cls.AZURE_EMBEDDINGS_FOLDER
}
@classmethod
def get_flask_config(cls) -> Dict[str, Any]:
"""Get Flask configuration dictionary"""
return {
'host': cls.FLASK_HOST,
'port': cls.FLASK_PORT,
'debug': cls.FLASK_DEBUG
}
class DevelopmentConfig(Config):
"""Development configuration"""
FLASK_DEBUG = True
INSIGHTFACE_CTX_ID = -1 # Use CPU for development
class ProductionConfig(Config):
"""Production configuration"""
FLASK_DEBUG = False
INSIGHTFACE_CTX_ID = 0 # Use GPU for production
FLASK_SECRET_KEY = os.getenv('FLASK_SECRET_KEY', 'change-this-in-production')
class TestingConfig(Config):
"""Testing configuration"""
FLASK_DEBUG = True
INSIGHTFACE_CTX_ID = -1
AZURE_CONTAINER_NAME = 'test-facematch-images'
USER_PREFERENCES_FILE = 'test_user_preferences.json'
# Configuration mapping
config_map = {
'development': DevelopmentConfig,
'production': ProductionConfig,
'testing': TestingConfig
}
def get_config(config_name: str = None) -> Config:
"""Get configuration based on environment"""
if config_name is None:
config_name = os.getenv('FLASK_ENV', 'development') or 'development'
return config_map.get(config_name, DevelopmentConfig)