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

Rotate Images to Upright Position in preprocess #6676

Merged
merged 7 commits into from Dec 7, 2023

Conversation

freddyaboulton
Copy link
Collaborator

Description

Closes: #6617

Added a unit test. Test visually by running image_mod_default_image with the rotated_image.jpeg saved in test/test_files.

The correct output is a 45 degree rotation from the upright position.

This branch

image

Main

image

🎯 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

  1. 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

  2. You may need to run the linters: bash scripts/format_backend.sh and bash scripts/format_frontend.sh

@gradio-pr-bot
Copy link
Contributor

gradio-pr-bot commented Dec 5, 2023

🪼 branch checks and previews

Name Status URL
Spaces ready! Spaces preview
Website ready! Website preview
Storybook ready! Storybook preview
Visual tests all good! Build review
🦄 Changes detected! Details

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:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

not used anywhere

@gradio-pr-bot
Copy link
Contributor

gradio-pr-bot commented Dec 5, 2023

🦄 change detected

This Pull Request includes changes to the following packages.

Package Version
gradio patch
  • Maintainers can select this checkbox to manually select packages to update.

With the following changelog entry.

Rotate Images to Upright Position in preprocess

Maintainers or the PR author can modify the PR title to modify this entry.

Something isn't right?

  • Maintainers can change the version label to modify the version bump.
  • If the bot has failed to detect any changes, or if this pull request needs to update multiple packages to different versions or requires a more comprehensive changelog entry, maintainers can update the changelog file directly.

@freddyaboulton freddyaboulton marked this pull request as ready for review December 5, 2023 23:17
@@ -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
Copy link
Member

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.

Copy link
Collaborator Author

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:
Copy link
Member

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

Copy link
Member

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()

Copy link
Collaborator Author

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

Copy link
Member

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

@abidlabs
Copy link
Member

abidlabs commented Dec 7, 2023

LGTM, just a tiny nit! Thanks @freddyaboulton

Copy link
Collaborator

@dawoodkhan82 dawoodkhan82 left a comment

Choose a reason for hiding this comment

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

Tested & lgtm

@freddyaboulton
Copy link
Collaborator Author

Thanks so much for the reviews!

@freddyaboulton freddyaboulton merged commit fe40308 into main Dec 7, 2023
23 of 24 checks passed
@freddyaboulton freddyaboulton deleted the 6617-image-rotation branch December 7, 2023 18:16
@pngwn pngwn mentioned this pull request Dec 7, 2023
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.

**Unexpected rotation after uploading an image!**
5 participants