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

Handle GIFs correct in gr.Image preprocessing #8589

Merged
merged 13 commits into from
Jun 20, 2024
Merged

Handle GIFs correct in gr.Image preprocessing #8589

merged 13 commits into from
Jun 20, 2024

Conversation

abidlabs
Copy link
Member

@abidlabs abidlabs commented Jun 20, 2024

We can finally handle GIFs in gr.Image closing one of our oldest issues! Fixes: #1965, Fixes: #5174

Screen Recording 2024-06-20 at 3 33 32 PM

Also removes up some old methods that are not used anymore

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Jun 20, 2024

🪼 branch checks and previews

Name Status URL
Spaces ready! Spaces preview
Website ready! Website preview
Storybook ready! Storybook preview
🦄 Changes detecting...

Install Gradio from this PR

pip install https://gradio-builds.s3.amazonaws.com/3922d7a636b0f7cccf4643b233201aa6dbd104c3/gradio-4.36.1-py3-none-any.whl

Install Gradio Python Client from this PR

pip install "gradio-client @ git+https://github.com/gradio-app/gradio@3922d7a636b0f7cccf4643b233201aa6dbd104c3#subdirectory=client/python"

Install Gradio JS Client from this PR

npm install https://gradio-builds.s3.amazonaws.com/3922d7a636b0f7cccf4643b233201aa6dbd104c3/gradio-client-1.1.1.tgz

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Jun 20, 2024

🦄 change detected

This Pull Request includes changes to the following packages.

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

With the following changelog entry.

Handle GIFs correct in gr.Image preprocessing

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.

Sorry, something went wrong.

abidlabs added 4 commits June 20, 2024 15:39
fix
@abidlabs abidlabs requested review from aliabid94, aliabd and pngwn June 20, 2024 19:45
Copy link
Collaborator

@aliabd aliabd left a comment

Choose a reason for hiding this comment

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

Hmm i'm still seeing a very weird issue..

Screen.Recording.2024-06-20.at.1.30.42.PM.mov

vs main

Screen.Recording.2024-06-20.at.1.33.14.PM.mov

with just

import gradio as gr
gr.Interface(lambda x:x, "image", "image").launch()

Maybe i'm not supposed to use defaults for gifs?

@abidlabs
Copy link
Member Author

Ok so basically by default, gr.Image() converts to a numpy array which is not valid for GIFs. For GIFS, you need to set type to either filepath or PIL. Let me add that to the docstrings

@aliabd
Copy link
Collaborator

aliabd commented Jun 20, 2024

@abidlabs got it, but it only works for filepath. with pil it's the same issue as main.

@abidlabs
Copy link
Member Author

Yeah hmm let me see

@abidlabs
Copy link
Member Author

Oh okay so what's happening is that when a PIL image is passed into a gr.Image() output component, the format parameter coerces it into the specified format, which is "webp" by default. So you'd need to do:

import gradio as gr

demo = gr.Interface(lambda x:x, gr.Image(type="pil"), gr.Image(format="gif"))
    
demo.launch()

or you can keep it as a filepath, like this:

import gradio as gr

demo = gr.Interface(lambda x:x, gr.Image(type="filepath"), "image")
    
demo.launch()

Slightly confusing, but I think its best we can do without a breakage

Copy link
Collaborator

@aliabd aliabd left a comment

Choose a reason for hiding this comment

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

Ok, i'm fine with it as is. Consider changing the docs a bit. You could even add a section on GIFs :)

Thanks!

@abidlabs
Copy link
Member Author

Yeah I'll do that!

abidlabs and others added 6 commits June 20, 2024 19:11
@abidlabs abidlabs enabled auto-merge (squash) June 20, 2024 23:20
@abidlabs abidlabs merged commit 34430b9 into main Jun 20, 2024
8 checks passed
@abidlabs abidlabs deleted the gifs branch June 20, 2024 23:25
This was referenced Jun 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants