""" Configuration settings for different deployment environments """ import os from pathlib import Path # Base directory BASE_DIR = Path(__file__).parent.parent # Detect environment ENVIRONMENT = os.environ.get('ENVIRONMENT', 'local') IS_DATABRICKS = os.environ.get('DATABRICKS_RUNTIME_VERSION') is not None # Local development settings LOCAL_CONFIG = { 'host': '127.0.0.1', 'port': 8050, 'debug': True, 'model_cache': str(BASE_DIR / 'cache'), 'upload_folder': str(BASE_DIR / 'uploads'), 'datasets_folder': str(BASE_DIR / 'datasets'), 'max_workers': 1, 'use_reloader': True } # Databricks deployment settings DATABRICKS_CONFIG = { 'host': '0.0.0.0', 'port': int(os.environ.get('DATABRICKS_APP_PORT', 8080)), 'debug': False, 'model_cache': '/tmp/model_cache', 'upload_folder': '/tmp/uploads', 'datasets_folder': '/dbfs/datasets', 'max_workers': 4, 'use_reloader': False } # Select configuration based on environment CONFIG = DATABRICKS_CONFIG if IS_DATABRICKS else LOCAL_CONFIG # Device configuration - defaults to CPU for HuggingFace Spaces, CUDA for others IS_HUGGINGFACE_SPACE = os.environ.get('SPACE_ID') is not None default_device = 'cpu' if IS_HUGGINGFACE_SPACE else 'cuda' DEVICE = os.environ.get('DEVICE', default_device) # 'cuda' (with CPU fallback), 'cpu', or 'auto' # Logging configuration LOG_LEVEL = os.environ.get('LOG_LEVEL', 'INFO' if not CONFIG['debug'] else 'DEBUG') LOG_FORMAT = '%(asctime)s - %(name)s - %(levelname)s - %(message)s' LOG_FILE = str(BASE_DIR / 'logs' / 'chronos2_app.log') # Create required directories def setup_directories(): """Create required directories if they don't exist""" for key in ['model_cache', 'upload_folder', 'datasets_folder']: path = Path(CONFIG[key]) path.mkdir(parents=True, exist_ok=True) # Create logs directory Path(LOG_FILE).parent.mkdir(parents=True, exist_ok=True) # Model configuration MODEL_CONFIG = { 'warmup_enabled': os.environ.get('MODEL_WARMUP', 'true').lower() == 'true', 'warmup_length': 100, 'warmup_horizon': 10, 'cache_enabled': True, 'memory_limit_gb': 6 } # App metadata APP_METADATA = { 'title': 'Chronos 2 Time Series Forecasting', 'subtitle': 'Production-Ready ML Model Testing Interface', 'version': '1.0.0', 'author': 'Your Organization' }