Download utils/quota.py from Hfzune/Test: direct link, hf CLI and curl.
- Browser
- Download file 719 Bytes
-
https://huggingface.co/spaces/Hfzune/Test/resolve/main/utils/quota.py
- Command line
-
hf download hf://spaces/Hfzune/Test/utils/quota.py
-
curl -L -o quota.py https://huggingface.co/spaces/Hfzune/Test/resolve/main/utils/quota.py
719 Bytes
| import logging | |
| from datetime import datetime, timezone | |
| from db.init import get_conn | |
| log = logging.getLogger("quota") | |
| SECONDS_LIMIT = 300 # free tier approximation | |
| def _today_prefix(): | |
| return datetime.now(timezone.utc).date().isoformat() | |
| def quota_snapshot() -> dict: | |
| prefix = _today_prefix() | |
| with get_conn() as conn: | |
| row = conn.execute( | |
| "SELECT COALESCE(SUM(duration_ms),0) AS ms, COUNT(*) AS c " | |
| "FROM gpu_log WHERE timestamp LIKE ?", | |
| (prefix + "%",), | |
| ).fetchone() | |
| ms = row["ms"] or 0 | |
| return { | |
| "seconds_used": ms / 1000.0, | |
| "seconds_limit": SECONDS_LIMIT, | |
| "turns_today": row["c"] or 0, | |
| "date": prefix, | |
| } |