Spaces:
Paused
Paused
Download app/engine/json_utils.py from petermutwiri/Mutsynchub: direct link, hf CLI and curl.
- Browser
- Download file 537 Bytes
-
https://huggingface.co/spaces/petermutwiri/Mutsynchub/resolve/main/app/engine/json_utils.py
- Command line
-
hf download hf://spaces/petermutwiri/Mutsynchub/app/engine/json_utils.py
-
curl -L -o json_utils.py https://huggingface.co/spaces/petermutwiri/Mutsynchub/resolve/main/app/engine/json_utils.py
537 Bytes
| # analytics-service/app/engine/json_utils.py | |
| import json | |
| from datetime import datetime, date | |
| import numpy as np | |
| class CustomJSONEncoder(json.JSONEncoder): | |
| def default(self, obj): | |
| if isinstance(obj, (datetime, date)): | |
| return obj.isoformat() | |
| if isinstance(obj, (np.integer, np.int64)): | |
| return int(obj) | |
| if isinstance(obj, (np.floating, np.float64)): | |
| return float(obj) | |
| if isinstance(obj, np.ndarray): | |
| return obj.tolist() | |
| return super().default(obj) |