Download src/utils/agent_state.py from 27bchao/web-ui: direct link, hf CLI and curl.
- Browser
- Download file 808 Bytes
-
https://huggingface.co/spaces/27bchao/web-ui/resolve/main/src/utils/agent_state.py
- Command line
-
hf download hf://spaces/27bchao/web-ui/src/utils/agent_state.py
-
curl -L -o agent_state.py https://huggingface.co/spaces/27bchao/web-ui/resolve/main/src/utils/agent_state.py
808 Bytes
| import asyncio | |
| class AgentState: | |
| _instance = None | |
| def __init__(self): | |
| if not hasattr(self, '_stop_requested'): | |
| self._stop_requested = asyncio.Event() | |
| self.last_valid_state = None # store the last valid browser state | |
| def __new__(cls): | |
| if cls._instance is None: | |
| cls._instance = super(AgentState, cls).__new__(cls) | |
| return cls._instance | |
| def request_stop(self): | |
| self._stop_requested.set() | |
| def clear_stop(self): | |
| self._stop_requested.clear() | |
| self.last_valid_state = None | |
| def is_stop_requested(self): | |
| return self._stop_requested.is_set() | |
| def set_last_valid_state(self, state): | |
| self.last_valid_state = state | |
| def get_last_valid_state(self): | |
| return self.last_valid_state |