Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compute visualization results from operators #4324

Merged
merged 4 commits into from
May 9, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion fiftyone/server/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
| `voxel51.com <https://voxel51.com/>`_
|
"""

from json import JSONEncoder
import traceback
import typing as t
import logging

from bson import json_util
import numpy as np

from fiftyone.core.utils import run_sync_task

Expand All @@ -18,6 +21,17 @@
from starlette.requests import Request


class Encoder(JSONEncoder):
def default(self, o):
if isinstance(o, np.floating):
return float(o)

if isinstance(o, np.integer):
return int(o)

return JSONEncoder.default(self, o)


def route(func):
async def wrapper(
endpoint: HTTPEndpoint, request: Request, *args
Expand All @@ -31,7 +45,9 @@ async def wrapper(
return response

return Response(
await run_sync_task(lambda: json_util.dumps(response))
await run_sync_task(
lambda: json_util.dumps(response, cls=Encoder)
)
)
except Exception as e:
logging.exception(e)
Expand Down
Loading