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

Reduce processed image display/downloading overhead #7486

Closed
1 task done
smikhai1 opened this issue Feb 20, 2024 · 6 comments · Fixed by #7680
Closed
1 task done

Reduce processed image display/downloading overhead #7486

smikhai1 opened this issue Feb 20, 2024 · 6 comments · Fixed by #7680
Assignees
Labels
enhancement New feature or request 🖼️ ImageEditor Perf performance-related

Comments

@smikhai1
Copy link

  • I have searched to see if a similar issue already exists.

Is your feature request related to a problem? Please describe.
In the Gradio library, processed images are saved in the PNG format by default, as observed in the save_img_array_to_cache and save_pil_to_cache functions within gradio.processing_utils module. This behavior results in significantly larger file sizes compared to the JPEG format: specifically, for 4K images, the PNG files are approximately 10 times larger than their JPEG counterparts. This leads to increased download and displaying times for the front end, adding unnecessary overhead to the user experience.

Describe the solution you'd like
To enhance flexibility and efficiency, it would be beneficial to allow users to select the file format for saving images in the Gradio cache. This could be implemented by introducing an additional parameter, such as format, to the constructors of all image-related components.

As an example, in my application I manually modified the default behavior of the aforementioned functions to save images in JPEG format, which significantly improved the results' delivery time and saved extra 10 seconds

Additional context
Add any other context or screenshots about the feature request here.

@pngwn pngwn added the Perf performance-related label Feb 20, 2024
@freddyaboulton
Copy link
Collaborator

Do you want to open a PR for this @smikhai1 ? I think we can add an img_format argument to gr.Image that controls the format the image is saved in when it's a numpy array or PIL image. cc @abidlabs

@abidlabs
Copy link
Member

Agreed. The name of parameter could be just format since we're already working with the gr.Image component and to mirror the similar format parameter in gr.Video

@abidlabs abidlabs added the enhancement New feature or request label Feb 21, 2024
@smikhai1
Copy link
Author

@freddyaboulton yeah, sure. I will make a PR

@freddyaboulton
Copy link
Collaborator

We should preserve the file format used during upload if possible see #7657

dfl added a commit to dfl/gradio that referenced this issue Mar 12, 2024
preserve file format during upload
add format to image component
dfl added a commit to dfl/gradio that referenced this issue Mar 12, 2024
preserve file format during upload
add format to image component
dfl added a commit to dfl/gradio that referenced this issue Mar 12, 2024
@dfl
Copy link
Contributor

dfl commented Mar 12, 2024

apologies I wasn't able to run the test suite locally 🙇‍♂️
had a bunch of dependency issues on my mac

hoping maybe someone can take this and run with it?

@freddyaboulton
Copy link
Collaborator

Hi @dfl ! Yea someone can get it over the finish line. Thanks for the PR again.

freddyaboulton pushed a commit to dfl/gradio that referenced this issue Mar 19, 2024
preserve file format during upload
add format to image component
freddyaboulton pushed a commit to dfl/gradio that referenced this issue Mar 19, 2024
abidlabs pushed a commit that referenced this issue Mar 19, 2024
…lot to control format to save image files in (#7680)

* WIP re: #7486. Make less PNG-centric.
preserve file format during upload
add format to image component

* more format preservation re: #7486

* lint

* lint; add comments; update Plot component

* add'l for Plot imaging defaults

* Working tests

* add changeset

* Add code

* test

* Add code

* add changeset

* Docstring improvements

---------

Co-authored-by: freddyaboulton <alfonsoboulton@gmail.com>
Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request 🖼️ ImageEditor Perf performance-related
Projects
None yet
5 participants