Spaces:
Running
Running
File size: 1,536 Bytes
25fc2cb |
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 |
import os
from datetime import timedelta
class Config:
"""Base configuration"""
# Flask
SECRET_KEY = os.environ.get('SECRET_KEY') or os.urandom(24)
# File Upload
UPLOAD_FOLDER = 'static/uploads/'
ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'webp'}
MAX_CONTENT_LENGTH = 16 * 1024 * 1024 # 16 MB
# Session
PERMANENT_SESSION_LIFETIME = timedelta(hours=1)
SESSION_COOKIE_SECURE = False
SESSION_COOKIE_HTTPONLY = True
SESSION_COOKIE_SAMESITE = 'Lax'
# Model
MODEL_NAME = "wambugu71/crop_leaf_diseases_vit"
# Logging
LOG_LEVEL = 'INFO'
class DevelopmentConfig(Config):
"""Development configuration"""
DEBUG = True
TESTING = False
class ProductionConfig(Config):
"""Production configuration"""
DEBUG = False
TESTING = False
SESSION_COOKIE_SECURE = True
# Rate limiting
RATELIMIT_ENABLED = True
RATELIMIT_DEFAULT = "100 per hour"
# Security headers
TALISMAN_FORCE_HTTPS = False # Set to True if using HTTPS
class TestingConfig(Config):
"""Testing configuration"""
DEBUG = True
TESTING = True
# Configuration dictionary
config = {
'development': DevelopmentConfig,
'production': ProductionConfig,
'testing': TestingConfig,
'default': DevelopmentConfig
}
def get_config(env=None):
"""Get configuration based on environment"""
if env is None:
env = os.environ.get('FLASK_ENV', 'development')
return config.get(env, config['default']) |