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

Add workaround to prevent importing gradio breaking PIL.Image.registered_extensions() #2846

Merged
merged 3 commits into from Dec 20, 2022

Conversation

aliencaocao
Copy link
Contributor

@aliencaocao aliencaocao commented Dec 19, 2022

Description

This is a Pillow issue but the folks at Pillow suggested a workaround in python-pillow/Pillow#6809 (comment)
Until Pillow merges python-pillow/Pillow#6811 and publishes a new release (in Jan 2023 according to python-pillow/Pillow#6750), this would be the only way to fix it.

The issue is importing matplotlib.figure will in turn import PIL.PngInfoPlugin, which causes existing extensions to not be initialized fully but only initialized with PNG formats. Thus, Image.init() have to be called before this import.

Closes: #2843

Checklist:

  • I have performed a self-review of my own code
  • I have added a short summary of my change to the CHANGELOG.md
  • My code follows the style guidelines of this project
  • I have commented my code in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@aliencaocao
Copy link
Contributor Author

All the failing tests are due to the use of Image.init() before importing matplotlib and others, however this is necessary for the fix

@abidlabs
Copy link
Member

Thanks for the PR @aliencaocao! I tested it and it works for me. However, it also works for me if you move include the line PIL.Image.init() after all of the import statements (e.g. to line 67, right above set_documentation_group("component"))

Can you try this and see if it works for you as well? That way, we can satisfy the linter as well

@aliencaocao
Copy link
Contributor Author

aliencaocao commented Dec 20, 2022

Hi thanks for pointing out. I tested and it indeed works. Already fixed my PR.

Although there are still failing tests indicated though not required

@abidlabs
Copy link
Member

Thank you @aliencaocao for making the update! Don't worry about the flaky tests, they're not related to your code. If all of the other tests pass, I'll merge this in

@abidlabs
Copy link
Member

Looks good! Thanks again @aliencaocao for the fix

@radarhere
Copy link

Pillow 9.4.0 has now been released

@aliencaocao
Copy link
Contributor Author

aliencaocao commented Jan 4, 2023

gradio 3.15 is also released, that version already includes a fix

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.

Gradio seems to break Pillow / PIL.Image format support
3 participants