Resolve Gallery base64 representation issues#2265
Conversation
|
Awesome, thank you so much for the PR @proxyphi! It looks like this is basically ready, right? If so, we can take look at why the tests are failing and fix that up. Thanks again! |
|
Hello! This is mostly ready, yes. I believe a couple of tests are breaking due to the move from I can only see one test, |
|
Sounds good, thanks for the explanation @proxyphi. Backend changes look good -- I made some minor cleanups to the docstrings. @aliabid94 would you be able to review the frontend changes? |
|
Thanks for fixing the tests @proxyphi! Opening this up for review |
| """ | ||
| component = gr.Image("test/test_files/bus.png") | ||
| self.assertEqual(component.get_config().get("value"), media_data.BASE64_IMAGE) | ||
| tmp_filename = component.get_config().get("value").get("name") |
There was a problem hiding this comment.
This is testing the processing_utils.encode_file_to_base64() function rather than the gr.Image.postprocess() function. Instead, we can use file comparisons (filecmp.cmp) to confirm that the postprocessed file is the same as the original file like we do for the Audio and Video components.
There was a problem hiding this comment.
The tests in test_examples.py are doing the same
|
@proxyphi testing the PR and right now, import gradio as gr
gr.Interface(lambda x:x, "image", "image", examples=["lion.jpg"]).launch() |
* change Image to derive from FileSerializable * handle potential dict output of Image, Audio, and Video breaking calls to HF API, and also breaking examples * add several tests and use filecmp where appropriate * handle FileData input to an input image component on frontend * ensure FileData input gets converted to b64 before being handed to sketch component
…gallery-b64-format
|
Just went ahead and committed some changes that should resolve that issue - I was running into it also. It was being caused by the serialization of the Image component effectively conflicting with the new output from postprocess. I've made some changes that should make Image more in line with the other media components, though I ran into some general issues revolving around FileSerializable data being passed through Examples, or when passed to the HF API. Some tests I've added with audio confirmed that it wasn't originally limited to the changes to Image. These should be mitigated now! But I've gone ahead and marked some TODO's where I felt things may need a closer look 😇 |
|
Thanks so much for making the fixes @proxyphi! Taking a look now |
…t would also show galleries on launch


Description
Resolves performance issues caused by base64 image representation in gr.Gallery and gr.Image.
Changes include:
Gallery.postprocessandImage.postprocessto store and serve tempfiles of images, in-line with how Audio and Video components are implementedGallery.svelteandImage.svelteUI components to handleFileData.normalise_fileinui/packages/upload/utils.ts: broke out array case handling into newnormalise_filesfunction.test_staticto expect filepath instead of base64 encoding.Opening this as a draft PR since I had been working on it the past few days, and noticed #2262 getting posted, so I thought it might be of use☺️
It does go beyond the original scope of the issue and serves Images as well, as I had run into severe performance issues on mobile when working with images beyond 1024x1024.
Closes: #2262
Checklist: