Spaces:
Sleeping
Sleeping
Download src/utils/config.py from Prashant-Mahto/vrag-pdf-reader: direct link, hf CLI and curl.
- Browser
- Download file 1.23 kB
-
https://huggingface.co/spaces/Prashant-Mahto/vrag-pdf-reader/resolve/main/src/utils/config.py
- Command line
-
hf download hf://spaces/Prashant-Mahto/vrag-pdf-reader/src/utils/config.py
-
curl -L -o config.py https://huggingface.co/spaces/Prashant-Mahto/vrag-pdf-reader/resolve/main/src/utils/config.py
1.23 kB
| """Reads config/config.yaml; explicit arguments always win.""" | |
| import os | |
| from functools import lru_cache | |
| import yaml | |
| CONFIG_PATH = os.environ.get("VRAG_CONFIG", "config/config.yaml") | |
| def load_config(path: str = CONFIG_PATH) -> dict: | |
| """The parsed config file (read once and cached); an empty dict when the file is missing.""" | |
| if not os.path.exists(path): | |
| print(f"[Config] {path} not found — falling back to built-in defaults.") | |
| return {} | |
| with open(path, "r", encoding="utf-8") as f: | |
| return yaml.safe_load(f) or {} | |
| def get(dotted_key: str, default=None): | |
| """get('retrieval.top_k_rerank', 3) -> value from config.yaml, or the default.""" | |
| # Read the module attribute at call time so VRAG_CONFIG (and tests) can redirect it. | |
| node = load_config(CONFIG_PATH) | |
| for part in dotted_key.split("."): | |
| if not isinstance(node, dict) or part not in node: | |
| return default | |
| node = node[part] | |
| return default if node is None else node | |
| def pick(explicit, dotted_key: str, default): | |
| """Explicit argument wins; otherwise config; otherwise the built-in default.""" | |
| return explicit if explicit is not None else get(dotted_key, default) | |