Spaces:
Sleeping
Sleeping
Download utils/secrets_utils.py from Markishime/ags: direct link, hf CLI and curl.
- Browser
- Download file 1.06 kB
-
https://huggingface.co/spaces/Markishime/ags/resolve/main/utils/secrets_utils.py
- Command line
-
hf download hf://spaces/Markishime/ags/utils/secrets_utils.py
-
curl -L -o secrets_utils.py https://huggingface.co/spaces/Markishime/ags/resolve/main/utils/secrets_utils.py
1.06 kB
| """Safe access helpers for Streamlit secrets on Hugging Face Spaces.""" | |
| from __future__ import annotations | |
| from typing import Any, Optional | |
| def secrets_available() -> bool: | |
| """Return True when Streamlit secrets are configured.""" | |
| try: | |
| import streamlit as st | |
| if not hasattr(st, "secrets"): | |
| return False | |
| _ = st.secrets.keys() | |
| return True | |
| except Exception: | |
| return False | |
| def has_secret(key: str) -> bool: | |
| """Check whether a top-level secret key exists without raising.""" | |
| try: | |
| import streamlit as st | |
| if not hasattr(st, "secrets"): | |
| return False | |
| return key in st.secrets | |
| except Exception: | |
| return False | |
| def get_secret_section(section: str) -> Optional[Any]: | |
| """Return a secrets section/namespace, or None if unavailable.""" | |
| try: | |
| import streamlit as st | |
| if not hasattr(st, "secrets") or section not in st.secrets: | |
| return None | |
| return st.secrets[section] | |
| except Exception: | |
| return None |