File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed
Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -284,6 +284,15 @@ def rank_path(self, path):
284284 return path , retval
285285
286286
287+ class NumpyEncoder (json .JSONEncoder ):
288+ """ Custom encoder for numpy data types """
289+ def default (self , obj ):
290+ if isinstance (obj , np .float32 ):
291+ return float (obj ) # Convert float32 to native float
292+ if isinstance (obj , np .ndarray ):
293+ return obj .tolist () # Convert arrays to list
294+ return json .JSONEncoder .default (self , obj )
295+
287296def application (environ , start_response ):
288297 """
289298 WSGI-compatible langid web service.
@@ -349,7 +358,7 @@ def application(environ, start_response):
349358
350359 headers = [('Content-type' , 'text/javascript; charset=utf-8' )] # HTTP Headers
351360 start_response (status , headers )
352- return [json .dumps (response )]
361+ return [json .dumps (response , cls = NumpyEncoder ). encode ( 'utf-8' )]
353362
354363
355364def main ():
You can’t perform that action at this time.
0 commit comments