Spaces:
Sleeping
Sleeping
Download logs.py from eishit32/UPNISO_API: direct link, hf CLI and curl.
- Browser
- Download file 563 Bytes
-
https://huggingface.co/spaces/eishit32/UPNISO_API/resolve/main/logs.py
- Command line
-
hf download hf://spaces/eishit32/UPNISO_API/logs.py
-
curl -L -o logs.py https://huggingface.co/spaces/eishit32/UPNISO_API/resolve/main/logs.py
563 Bytes
| import time | |
| from collections import defaultdict | |
| # Store logs (replace with DB later) | |
| USAGE_LOGS = defaultdict(list) | |
| def log_request(api_key: str, endpoint: str): | |
| USAGE_LOGS[api_key].append({ | |
| "endpoint": endpoint, | |
| "time": int(time.time()) | |
| }) | |
| def get_usage(api_key: str): | |
| return USAGE_LOGS.get(api_key, []) | |
| def stats(): | |
| report = {} | |
| for key, logs in USAGE_LOGS.items(): | |
| report[key] = { | |
| "total_requests": len(logs), | |
| "last_used": logs[-1]["time"] if logs else None | |
| } | |
| return report | |