Download src/storage/state.py from Akcom/test: direct link, hf CLI and curl.
- Browser
- Download file 921 Bytes
-
https://huggingface.co/spaces/Akcom/test/resolve/main/src/storage/state.py
- Command line
-
hf download hf://spaces/Akcom/test/src/storage/state.py
-
curl -L -o state.py https://huggingface.co/spaces/Akcom/test/resolve/main/src/storage/state.py
921 Bytes
| import time | |
| from src.utils.singleton import Singleton | |
| from src.modules.logger import logger as Logger | |
| class State: | |
| __metaclass__ = Singleton | |
| def __init__(self): | |
| # Common | |
| self._lock = False | |
| self._time_start = None | |
| # Prediction | |
| self._current_image = None | |
| def _check_lock_assert(self): | |
| if self._lock: | |
| raise Exception('State locked') | |
| # State begin - end | |
| def begin(self): | |
| self._check_lock_assert() | |
| self._lock = True | |
| self._time_start = time.time() | |
| Logger.info(f"Started at: {self._time_start}") | |
| def end(self): | |
| self._lock = False | |
| Logger.info(f"Stopped at: {time.time()}") | |
| def set_current_image(self, image): | |
| Logger.info(f"Set current image: {image}") | |
| self._current_image = image | |
| def get_current_image(self): | |
| return self._current_image | |
| state = State() | |