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 correctly in Image component #1965

Open
1 task done
AlicanAKCA opened this issue Aug 7, 2022 · 6 comments
Open
1 task done

Handle GIFs correctly in Image component #1965

AlicanAKCA opened this issue Aug 7, 2022 · 6 comments
Labels
bug Something isn't working 🖼️ image Image component Priority High priority issues
Milestone

Comments

@AlicanAKCA
Copy link

AlicanAKCA commented Aug 7, 2022

Describe the bug

Hello, I had tried to upload GIF. I encountered an issue. I saw that when I wanted to split the GIF file frame by frame, it only took the first frame. This situation occurs in both local and embedded environments. Here's the code:

#fname is a filename giving by input. You can see the output below. 
 def GIF(fname,pixel_size):
    print(fname)
    gif = Image.open(fname)
    frames = []
    for i in range(gif.n_frames):
        gif.seek(i)
        frame = Image.new('RGB', gif.size)
        frame.paste(gif)
        frame = np.array(frame)
        frames.append(frame)
    print(len(frames))
inputs_tab1 = [gr.inputs.Image(type='file', label="Image"),
               gr.Slider(4, 100, value=12, step = 2, label="Pixel Size")]
outputs_tab1 = [gr.Image(type="file",label="Front")]

gr.Interface(fn = GIF,
                    inputs = inputs_tab1,
                    outputs = outputs_tab1).launch()

Output:

'C:\Users\alica\AppData\Local\Temp\tmpk4__6naz.gif' # print(fname)
1 # print(len(frames)) 

As you can see, there is only one frame of GIF file. I didn't encounter this issue when I wasn't using the Gradio. But, I want to implement this code on Gradio for GIF processing. Gradio just taking the first frame of GIF.

Is there an existing issue for this?

  • I have searched the existing issues

Reproduction

You can try to upload GIF on Huggingface Space. But, It will not return anything. You have to check out the logs.

Screenshot

No response

Logs

To create a public link, set `share=True` in `launch()`.
/tmp/tmp4ze2data.gif
1

System Info

Gradio 3.1.0

Severity

annoying

@AlicanAKCA AlicanAKCA added the bug Something isn't working label Aug 7, 2022
@JunyaoHu
Copy link

hello, have you solved it?

@ThePyceIsRight
Copy link

I am also curious if you figured this out.

@AlicanAKCA AlicanAKCA reopened this Jun 23, 2023
@AlicanAKCA
Copy link
Author

No, I couldn't.

@ThePyceIsRight
Copy link

ThePyceIsRight commented Jul 10, 2023

No, I couldn't.

@AlicanAKCA

What if instead of creating a new image (frame) and pasting the original, you did:

frame = img.seek(i)
frame.convert('RGBA')
frame = np.array(frame)

That's how I would do it. I still don't see why your method failed though.

Edit: please just ignore my comment - for some reason I was reading this for the PIL library, not Gradio

@ThePyceIsRight
Copy link

I am also experiencing this same issue. The only way I've found to upload a gif with all frames to Image component is to provide the path to a hard drive file. A less elegant workaround that I've been using is to use the File component to upload the gif and then save the gif to hard drive and then input the hard drive gif to an Image component.

Would be really nice if the Image component could just accept an animated gif via drag and drop and hold it for use in the code.

@abidlabs abidlabs changed the title GIF Cannot Be Uploaded Handle GIFs correctly in Image component Sep 29, 2023
@abidlabs abidlabs added the 🖼️ image Image component label Sep 29, 2023
@abidlabs abidlabs added this to the 4.0 milestone Sep 29, 2023
@abidlabs abidlabs modified the milestones: 4.0, 4.0-image Oct 23, 2023
@abidlabs abidlabs added the Priority High priority issues label Feb 2, 2024
@dfl
Copy link
Contributor

dfl commented Mar 11, 2024

I'm guessing this is related to converting everything to PNG on the backend c.f. #7486

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working 🖼️ image Image component Priority High priority issues
Projects
None yet
Development

No branches or pull requests

5 participants