Spaces:
Sleeping
Sleeping
Download src/utils/helper.py from ABAO77/Run_code_api: direct link, hf CLI and curl.
- Browser
- Download file 526 Bytes
-
https://huggingface.co/spaces/ABAO77/Run_code_api/resolve/c5ca6dc624a28126c87badbaed52fccda6c1e7f5/src/utils/helper.py
- Command line
-
hf download hf://spaces/ABAO77/Run_code_api@c5ca6dc624a28126c87badbaed52fccda6c1e7f5/src/utils/helper.py
-
curl -L -o helper.py https://huggingface.co/spaces/ABAO77/Run_code_api/resolve/c5ca6dc624a28126c87badbaed52fccda6c1e7f5/src/utils/helper.py
526 Bytes
| import numpy as np | |
| def convert_numpy_types(obj): | |
| """Convert numpy types to Python native types""" | |
| if isinstance(obj, np.integer): | |
| return int(obj) | |
| elif isinstance(obj, np.floating): | |
| return float(obj) | |
| elif isinstance(obj, np.ndarray): | |
| return obj.tolist() | |
| elif isinstance(obj, dict): | |
| return {key: convert_numpy_types(value) for key, value in obj.items()} | |
| elif isinstance(obj, list): | |
| return [convert_numpy_types(item) for item in obj] | |
| else: | |
| return obj | |