Download app/utils.py from minhvh/her: direct link, hf CLI and curl.
- Browser
- Download file 1.09 kB
-
https://huggingface.co/spaces/minhvh/her/resolve/main/app/utils.py
- Command line
-
hf download hf://spaces/minhvh/her/app/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/minhvh/her/resolve/main/app/utils.py
1.09 kB
| """Utility functions for the Cloud Browser API.""" | |
| import logging | |
| import asyncio | |
| import psutil | |
| from typing import Dict, Any, List | |
| # Configure logging | |
| logging.basicConfig(level=logging.INFO) | |
| logger = logging.getLogger(__name__) | |
| def setup_logger(): | |
| """Set up and return the logger.""" | |
| return logger | |
| async def get_loop_time(): | |
| """Get the current event loop time.""" | |
| return asyncio.get_event_loop().time() | |
| def get_memory_usage(): | |
| """Get the current system memory usage as a percentage.""" | |
| return psutil.virtual_memory().percent | |
| def clean_browser_references( | |
| browser_id: str, | |
| browser_instances: Dict[str, Any], | |
| browser_contexts: Dict[str, Any], | |
| browser_pages: Dict[str, Any], | |
| browser_clients: Dict[str, List], | |
| ): | |
| """Remove all references to a browser instance.""" | |
| if browser_id in browser_instances: | |
| del browser_instances[browser_id] | |
| for collection in [browser_contexts, browser_pages, browser_clients]: | |
| if browser_id in collection: | |
| del collection[browser_id] # Fixed: changed 'bid' to 'browser_id' | |