import os import attrs @attrs.define(frozen=True) class AppConfigModel: production: bool hugging_face_token: str def get_env_or_warn(key: str): result = os.getenv(key) if (result is None) or (result.strip() == ""): print(f"Warning: could not find environment variable {key}") return "" return result def get_env_or_throw(key: str) -> str: result = os.getenv(key) if (result is None) or (result.strip() == ""): raise Exception(f"Could not obtain environment variable {key}") return result def get_app_config() -> AppConfigModel: is_production = get_env_or_warn("DEPLOYMENT_ENVIRONMENT").upper() == "PRODUCTION" if is_production: hugging_face_token = get_env_or_throw("HUGGING_FACE_TOKEN") else: hugging_face_token = get_env_or_warn("HUGGING_FACE_TOKEN") return AppConfigModel( production=is_production, hugging_face_token=hugging_face_token ) APP_CONFIG = get_app_config()