Spaces:
Sleeping
Sleeping
main.py
CHANGED
@@ -244,3 +244,33 @@ def prcess_ticker(ticker: str):
|
|
244 |
result = run_xgboost(df)
|
245 |
|
246 |
return json.dumps(result, cls=NumpyEncoder)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
244 |
result = run_xgboost(df)
|
245 |
|
246 |
return json.dumps(result, cls=NumpyEncoder)
|
247 |
+
|
248 |
+
|
249 |
+
class NumpyEncoder(json.JSONEncoder):
|
250 |
+
"""Custom encoder for numpy data types"""
|
251 |
+
|
252 |
+
def default(self, obj):
|
253 |
+
if isinstance(obj, np.ndarray):
|
254 |
+
return obj.tolist()
|
255 |
+
if isinstance(
|
256 |
+
obj,
|
257 |
+
(
|
258 |
+
np.int_,
|
259 |
+
np.intc,
|
260 |
+
np.intp,
|
261 |
+
np.int8,
|
262 |
+
np.int16,
|
263 |
+
np.int32,
|
264 |
+
np.int64,
|
265 |
+
np.uint8,
|
266 |
+
np.uint16,
|
267 |
+
np.uint32,
|
268 |
+
np.uint64,
|
269 |
+
),
|
270 |
+
):
|
271 |
+
return int(obj)
|
272 |
+
if isinstance(obj, (np.float_, np.float16, np.float32, np.float64)):
|
273 |
+
return float(obj)
|
274 |
+
if isinstance(obj, (np.complex_, np.complex64, np.complex128)):
|
275 |
+
return {"real": obj.real, "imag": obj.imag}
|
276 |
+
return json.JSONEncoder.default(self, obj)
|