Download config.py from rastof9/fb: direct link, hf CLI and curl.
- Browser
- Download file 2.11 kB
-
https://huggingface.co/spaces/rastof9/fb/resolve/main/config.py
- Command line
-
hf download hf://spaces/rastof9/fb/config.py
-
curl -L -o config.py https://huggingface.co/spaces/rastof9/fb/resolve/main/config.py
2.11 kB
| import os | |
| from pathlib import Path | |
| class Config: | |
| # Use a default secret key for development, but warn about it | |
| SECRET_KEY = os.getenv('SECRET_KEY', 'dev-secret-key-change-in-production') | |
| if SECRET_KEY == 'dev-secret-key-change-in-production': | |
| print("WARNING: Using default SECRET_KEY. This is insecure and should be changed in production.") | |
| # Use SQLite for simplicity | |
| SQLALCHEMY_DATABASE_URI = os.getenv('DATABASE_URL', 'sqlite:///app.db') | |
| SQLALCHEMY_TRACK_MODIFICATIONS = False | |
| # Use SQLite for Celery broker instead of Redis | |
| CELERY_BROKER_URL = os.getenv('CELERY_BROKER_URL', 'sqla+sqlite:///celery.db') | |
| CELERY_RESULT_BACKEND = os.getenv('CELERY_RESULT_BACKEND', 'db+sqlite:///celery-results.db') | |
| # Use a mock API key for development if not provided | |
| OPENAI_API_KEY = os.getenv('OPENAI_API_KEY', 'sk-mock-key-for-development') | |
| if OPENAI_API_KEY == 'sk-mock-key-for-development': | |
| print("WARNING: Using mock OPENAI_API_KEY. API calls will fail in production.") | |
| # Ensure instance path exists | |
| INSTANCE_PATH = os.getenv('INSTANCE_PATH', '/tmp/instance') | |
| Path(INSTANCE_PATH).mkdir(parents=True, exist_ok=True) | |
| class DevelopmentConfig(Config): | |
| DEBUG = True | |
| TESTING = False | |
| class ProductionConfig(Config): | |
| DEBUG = False | |
| TESTING = False | |
| # In production, we require real values for these settings | |
| def __init__(self): | |
| if self.SECRET_KEY == 'dev-secret-key-change-in-production': | |
| raise ValueError("Production requires a real SECRET_KEY") | |
| if self.OPENAI_API_KEY == 'sk-mock-key-for-development': | |
| raise ValueError("Production requires a real OPENAI_API_KEY") | |
| class TestingConfig(Config): | |
| TESTING = True | |
| DEBUG = True | |
| SQLALCHEMY_DATABASE_URI = 'sqlite:///:memory:' | |
| # Function to determine which config to use | |
| def get_config(): | |
| env = os.getenv('FLASK_ENV', 'development') | |
| if env == 'production': | |
| return ProductionConfig() | |
| elif env == 'testing': | |
| return TestingConfig() | |
| else: | |
| return DevelopmentConfig() |