Spaces:
Sleeping
Sleeping
Download env_loader.py from saheb/content-moderation-env: direct link, hf CLI and curl.
- Browser
- Download file 582 Bytes
-
https://huggingface.co/spaces/saheb/content-moderation-env/resolve/main/env_loader.py
- Command line
-
hf download hf://spaces/saheb/content-moderation-env/env_loader.py
-
curl -L -o env_loader.py https://huggingface.co/spaces/saheb/content-moderation-env/resolve/main/env_loader.py
582 Bytes
| from __future__ import annotations | |
| import os | |
| from pathlib import Path | |
| from dotenv import load_dotenv | |
| def load_environment(root: str | Path | None = None) -> str | None: | |
| """Load .env only when LOAD_ENV_FILE is enabled.""" | |
| project_root = Path(root) if root is not None else Path(__file__).resolve().parent | |
| should_load = os.getenv("LOAD_ENV_FILE", "").strip().lower() in {"1", "true", "yes", "on"} | |
| env_path = project_root / ".env" | |
| if should_load and env_path.exists(): | |
| load_dotenv(env_path, override=False) | |
| return str(env_path) | |
| return None | |