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
Rotate Images to Upright Position in preprocess #6676
Conversation
🪼 branch checks and previews
Install Gradio from this PR pip install https://gradio-builds.s3.amazonaws.com/40c01c121762aed57d4dd8220efb5ebf7b12be4b/gradio-4.8.0-py3-none-any.whl Install Gradio Python Client from this PR pip install "gradio-client @ git+https://github.com/gradio-app/gradio@40c01c121762aed57d4dd8220efb5ebf7b12be4b#subdirectory=client/python" |
@@ -58,21 +58,6 @@ def extract_base64_data(x: str) -> str: | |||
######################### | |||
|
|||
|
|||
def decode_base64_to_image(encoding: str) -> Image.Image: |
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.
not used anywhere
🦄 change detectedThis Pull Request includes changes to the following packages.
With the following changelog entry.
Maintainers or the PR author can modify the PR title to modify this entry.
|
gradio/components/image.py
Outdated
@@ -8,7 +8,8 @@ | |||
|
|||
import numpy as np | |||
from gradio_client.documentation import document, set_documentation_group | |||
from PIL import Image as _Image # using _ to minimize namespace pollution | |||
from PIL import Image as _Image | |||
from PIL import ImageOps # using _ to minimize namespace pollution |
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.
nit: This comment should be in the previous line.
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.
Yea I think black actually did this cause I originally placed both imports in the same line and it complained about length. Will fix!
if exif.get(274, 1) != 1 and hasattr(ImageOps, "exif_transpose"): | ||
try: | ||
im = ImageOps.exif_transpose(im) | ||
except Exception: |
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.
is it a good idea to raise an exception here, as it would error out the gradio app? I think a warning and then returning the original image would be better
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.
Oh sorry I just realized you catch the exception. But I think warnings.warn()
would be better than print()
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.
I'm not raising an exception here - I'm catching it and printing a message instage. Should be the same behavior as decode_base64_to_image
but without log.warning
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.
Yes sorry I parsed it incorrectly. But a warnings.warn would be better imo
LGTM, just a tiny nit! Thanks @freddyaboulton |
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.
Tested & lgtm
65d4e0e
to
8613c54
Compare
Thanks so much for the reviews! |
Description
Closes: #6617
Added a unit test. Test visually by running
image_mod_default_image
with therotated_image.jpeg
saved intest/test_files
.The correct output is a 45 degree rotation from the upright position.
This branch
Main
🎯 PRs Should Target Issues
Before your create a PR, please check to see if there is an existing issue for this change. If not, please create an issue before you create this PR, unless the fix is very small.
Not adhering to this guideline will result in the PR being closed.
Tests
PRs will only be merged if tests pass on CI. To run the tests locally, please set up your Gradio environment locally and run the tests:
bash scripts/run_all_tests.sh
You may need to run the linters:
bash scripts/format_backend.sh
andbash scripts/format_frontend.sh