Spaces:
Sleeping
Sleeping
File size: 1,701 Bytes
98a79a7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | """
Configuration loader utility
"""
import yaml
import os
import logging
logger = logging.getLogger(__name__)
def load_config(config_path: str = 'config.yaml') -> dict:
"""
Load configuration from YAML file
Args:
config_path: Path to configuration file
Returns:
config: Configuration dictionary
"""
try:
if not os.path.exists(config_path):
logger.error(f"Configuration file not found: {config_path}")
raise FileNotFoundError(f"Config file not found: {config_path}")
with open(config_path, 'r') as f:
config = yaml.safe_load(f)
logger.info(f"✓ Configuration loaded from {config_path}")
return config
except Exception as e:
logger.error(f"Failed to load configuration: {e}")
raise
def validate_config(config: dict) -> bool:
"""
Validate configuration values
Args:
config: Configuration dictionary
Returns:
valid: True if configuration is valid
"""
required_keys = ['model', 'video', 'crowd', 'heatmap', 'dashboard']
for key in required_keys:
if key not in config:
logger.error(f"Missing required configuration section: {key}")
return False
# Validate threshold values
if not 0 <= config['model']['confidence_threshold'] <= 1:
logger.error("Invalid confidence threshold (must be 0-1)")
return False
if not 0 <= config['heatmap']['alpha'] <= 1:
logger.error("Invalid heatmap alpha (must be 0-1)")
return False
logger.info("✓ Configuration validation passed")
return True
|