-
Notifications
You must be signed in to change notification settings - Fork 53
Implements Pillow image generation example #49
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
base: main
Are you sure you want to change the base?
Conversation
| image_bytes = buffer.getvalue() | ||
|
|
||
| # Create and return response with appropriate headers | ||
| return Response( | ||
| to_js(image_bytes).buffer, | ||
| headers={ | ||
| "Content-Type": content_type, | ||
| "Cache-Control": "public, max-age=3600", | ||
| }, | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One copy instead of two:
| image_bytes = buffer.getvalue() | |
| # Create and return response with appropriate headers | |
| return Response( | |
| to_js(image_bytes).buffer, | |
| headers={ | |
| "Content-Type": content_type, | |
| "Cache-Control": "public, max-age=3600", | |
| }, | |
| ) | |
| image_bytes = create_proxy(buffer.getvalue()) | |
| jsbuffer = image_bytes.getBuffer() | |
| try: | |
| # Create and return response with appropriate headers | |
| return Response( | |
| jsbuffer.data, | |
| headers={ | |
| "Content-Type": content_type, | |
| "Cache-Control": "public, max-age=3600", | |
| }, | |
| ) | |
| finally: | |
| image_bytes.destroy() | |
| jsbuffer.release() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
12-image-gen/src/entry.py
Outdated
| Return an HTML page showing available endpoints and examples. | ||
| """ | ||
| html = """ | ||
| <!DOCTYPE html> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we move this into it's own .html file and do
endpoints = Path(__file__).parent / "endpoints.html"
return Response(endpoints.read_text(), headers={"Content-Type": "text/html"})There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, this is a great example too that we should put in our docs somewhere
08c0160 to
eb78296
Compare
1188ea0 to
2a53cd0
Compare
3ee838b to
2458136
Compare
for more information, see https://pre-commit.ci

Deployed URL: https://python-image-gen.runtime-playground.workers.dev
Mostly generated using GenAI.
CC @ryanking13