Download persist.py from huggingface/Model_Cards_Writing_Tool: direct link, hf CLI and curl.
- Browser
- Download file 652 Bytes
-
https://huggingface.co/spaces/huggingface/Model_Cards_Writing_Tool/resolve/main/persist.py
- Command line
-
hf download hf://spaces/huggingface/Model_Cards_Writing_Tool/persist.py
-
curl -L -o persist.py https://huggingface.co/spaces/huggingface/Model_Cards_Writing_Tool/resolve/main/persist.py
652 Bytes
| # Thank god this existed. | |
| # https://gist.github.com/okld/0aba4869ba6fdc8d49132e6974e2e662 | |
| from streamlit import session_state as _state | |
| _PERSIST_STATE_KEY = f"{__name__}_PERSIST" | |
| def persist(key: str) -> str: | |
| """Mark widget state as persistent.""" | |
| if _PERSIST_STATE_KEY not in _state: | |
| _state[_PERSIST_STATE_KEY] = set() | |
| _state[_PERSIST_STATE_KEY].add(key) | |
| return key | |
| def load_widget_state(): | |
| """Load persistent widget state.""" | |
| if _PERSIST_STATE_KEY in _state: | |
| _state.update({ | |
| key: value | |
| for key, value in _state.items() | |
| if key in _state[_PERSIST_STATE_KEY] | |
| }) |