Spaces:
Running
Running
Download src/utils/configs.py from UNNAILab/EpInflammAge: direct link, hf CLI and curl.
- Browser
- Download file 814 Bytes
-
https://huggingface.co/spaces/UNNAILab/EpInflammAge/resolve/main/src/utils/configs.py
- Command line
-
hf download hf://spaces/UNNAILab/EpInflammAge/src/utils/configs.py
-
curl -L -o configs.py https://huggingface.co/spaces/UNNAILab/EpInflammAge/resolve/main/src/utils/configs.py
814 Bytes
| import os | |
| from omegaconf import OmegaConf | |
| from pytorch_tabular.config import ModelConfig | |
| from pytorch_tabular.utils import getattr_nested | |
| def read_parse_config(config, cls): | |
| if isinstance(config, str): | |
| if os.path.exists(config): | |
| _config = OmegaConf.load(config) | |
| if cls == ModelConfig: | |
| cls = getattr_nested(_config._module_src, _config._config_name) | |
| config = cls( | |
| **{ | |
| k: v | |
| for k, v in _config.items() | |
| if (k in cls.__dataclass_fields__.keys()) and (cls.__dataclass_fields__[k].init) | |
| } | |
| ) | |
| else: | |
| raise ValueError(f"{config} is not a valid path") | |
| config = OmegaConf.structured(config) | |
| return config | |