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

Do not store a temporary file #11

Closed
julien-c opened this issue Jul 10, 2020 · 3 comments · Fixed by #12
Closed

Do not store a temporary file #11

julien-c opened this issue Jul 10, 2020 · 3 comments · Fixed by #12
Labels
enhancement New feature or request

Comments

@julien-c
Copy link

Great article and tutorial @davidefiocco!

Just a tiny detail but I'm pretty sure you can just send the binary data from the image using https://pillow.readthedocs.io/en/latest/reference/Image.html#PIL.Image.Image.tobytes and a raw starlette.Response

Would love to read more about those subjects in the future!

@davidefiocco davidefiocco linked a pull request Jul 10, 2020 that will close this issue
@davidefiocco
Copy link
Owner

davidefiocco commented Jul 10, 2020

Hi @julien-c ! Thanks for your interest and feedback!

That's a good point, those tempfiles would eventually accumulate and crash the container...

Following your suggestion, I tried as a possibly better solution in #12:

bytes_io = io.BytesIO()
segmented_image.save(bytes_io, format='PNG')
return Response(bytes_io.getvalue(), media_type="image/png")

Let me know if this looks OK or you have better options in mind: I avoided using to_bytes because it returns the raw image data from the internal storage, and in my attempts the annotated image didn't render fine in the FastAPI documentation page.

@julien-c
Copy link
Author

Oh yeah, looks perfect that way.

davidefiocco pushed a commit to davidefiocco/davidefiocco.github.io that referenced this issue Jul 10, 2020
@davidefiocco
Copy link
Owner

Cool! I updated the post https://davidefiocco.github.io/2020/06/27/streamlit-fastapi-ml-serving.html accordingly, and I am closing this.

Thanks again @julien-c , indeed that'd be great to keep the content coming, let's see how it goes! :)

@davidefiocco davidefiocco added the enhancement New feature or request label May 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants