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

Update closed loop server with new interface #9

Merged
merged 3 commits into from
Apr 30, 2024
Merged

Conversation

wljungbergh
Copy link
Collaborator

Update the closed-loop server

  • Removing async definitions
  • Serialize tensor directly instead of converting to PNG ⚡

@wljungbergh wljungbergh requested a review from atonderski April 26, 2024 15:00
@atonderski
Copy link
Collaborator

I wonder if it would be better to allow for both raw tensors as well as actual images. Raw tensors are great if running on the same local connection (or even machine), but it could be horribly slow in other settings.

@atonderski
Copy link
Collaborator

atonderski commented Apr 26, 2024

maybe something like this:

class ImageFormat(str, Enum):
    raw = "raw"
    png = "png"
    jpg = "jpg"

@app.get("/image/")
async def get_image(format: ImageFormat = ImageFormat.jpg):
    image_bytes = get_image_bytes(format)  # Assuming get_image_bytes() method exists
    if format in (ImageFormat.jpg, ImageFormat.png):
        return Response(content=image_bytes, media_type=f"image/{format.value}")
    else:
        return PlainTextResponse(content=image_bytes, media_type="text/plain")

Alternatively, yours truly chatgpt suggested this, dunno if nice

    if format == ImageFormat.raw:
        return StreamingResponse(iter([image_bytes]), media_type="image/jpeg")
    elif format == ImageFormat.png:
        return StreamingResponse(iter([image_bytes]), media_type="image/png")
    elif format == ImageFormat.jpg:
        return StreamingResponse(iter([image_bytes]), media_type="image/jpeg")

@wljungbergh
Copy link
Collaborator Author

I like it. I added options for raw, png, and jpeg/jpg. However, I didn't change to the streaming response for now.

Copy link
Collaborator

@atonderski atonderski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for fixing, lgtm now!

@atonderski atonderski merged commit 3ec1c83 into main Apr 30, 2024
1 check passed
@atonderski atonderski deleted the modify_cl_server branch April 30, 2024 08:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants