Download core/globals.py from lhc-lab/AI-Colab: direct link, hf CLI and curl.
- Browser
- Download file 859 Bytes
-
https://huggingface.co/datasets/lhc-lab/AI-Colab/resolve/main/core/globals.py
- Command line
-
hf download hf://datasets/lhc-lab/AI-Colab/core/globals.py
-
curl -L -o globals.py https://huggingface.co/datasets/lhc-lab/AI-Colab/resolve/main/core/globals.py
859 Bytes
| """ | |
| This module provides centralized getters for global objects, ensuring lazy initialization | |
| and efficient access across the AIColab application. | |
| """ | |
| from typing import Any | |
| _globals: dict[str, Any] = {} | |
| def set_global(key: str, value: Any) -> None: | |
| """Sets a global object.""" | |
| _globals[key] = value | |
| def get_global(key: str) -> Any: | |
| """Gets a global object.""" | |
| return _globals.get(key) | |
| def initialize_global(key: str, initializer: Any) -> Any: | |
| """ | |
| Initializes a global object if it doesn't exist, using the provided initializer. | |
| Returns the initialized or existing global object. | |
| """ | |
| if key not in _globals: | |
| _globals[key] = initializer() | |
| return _globals[key] | |
| # Example usage (will be removed or modified as needed) | |
| # def get_logger(): | |
| # return initialize_global("logger", lambda: create_new_logger()) | |