File size: 2,365 Bytes
fc813d5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0a9ce4b
 
 
 
fc813d5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0a9ce4b
fc813d5
 
 
 
 
 
 
 
 
 
 
 
 
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
67
68
69
70
71
72
73
74
75
76
77
78
"""
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'
}