-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
88 lines (66 loc) · 2.45 KB
/
config.py
File metadata and controls
88 lines (66 loc) · 2.45 KB
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
79
80
81
82
83
84
85
86
87
88
"""
Configuration management for NeuroScan application.
Provides environment-specific settings for development, staging, and production.
"""
import os
from typing import Dict, Any
class Config:
"""Base configuration class."""
# Flask
SECRET_KEY = os.getenv('SECRET_KEY', 'dev-secret-key-change-in-production')
# Application
UPLOAD_FOLDER = os.getenv('UPLOAD_FOLDER', 'Uploads')
MAX_CONTENT_LENGTH = int(os.getenv('MAX_CONTENT_LENGTH', 16 * 1024 * 1024))
ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'bmp'}
# Model
MODEL_PATH = os.getenv('MODEL_PATH', 'mobilenet_brain_tumor_classifier.h5')
MODEL_URL = os.getenv('MODEL_URL', '')
# Dataset
DATASET_PATH = os.getenv('DATASET_PATH', './Dataset')
# Cache
CACHE_FOLDER = os.getenv('CACHE_FOLDER', './cache')
CACHE_DURATION = int(os.getenv('CACHE_DURATION', 3600))
# Rate Limiting
RATELIMIT_ENABLED = os.getenv('RATELIMIT_ENABLED', 'true').lower() == 'true'
RATELIMIT_DEFAULT = os.getenv('RATE_LIMIT', '10 per minute')
RATELIMIT_STORAGE_URL = os.getenv('RATELIMIT_STORAGE_URL', 'memory://')
# Logging
LOG_LEVEL = os.getenv('LOG_LEVEL', 'INFO')
LOG_FORMAT = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
@staticmethod
def init_app(app):
"""Initialize application with this config."""
pass
class DevelopmentConfig(Config):
"""Development environment configuration."""
DEBUG = True
TESTING = False
LOG_LEVEL = 'DEBUG'
class ProductionConfig(Config):
"""Production environment configuration."""
DEBUG = False
TESTING = False
@staticmethod
def init_app(app):
"""Production-specific initialization."""
Config.init_app(app)
# Ensure critical environment variables are set
if not os.getenv('SECRET_KEY'):
raise ValueError("SECRET_KEY must be set in production")
class TestingConfig(Config):
"""Testing environment configuration."""
DEBUG = True
TESTING = True
RATELIMIT_ENABLED = False
# Configuration dictionary
config: Dict[str, Any] = {
'development': DevelopmentConfig,
'production': ProductionConfig,
'testing': TestingConfig,
'default': DevelopmentConfig
}
def get_config(env: str = None) -> Config:
"""Get configuration for specified environment."""
if env is None:
env = os.getenv('FLASK_ENV', 'development')
return config.get(env, config['default'])