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

Fix the download button of the gr.Gallery() component to work #6487

Merged
merged 26 commits into from Dec 9, 2023

Conversation

whitphx
Copy link
Member

@whitphx whitphx commented Nov 19, 2023

Description

Fix the bug of the download button on gr.Gallery().

Closes: #6486

@gradio-pr-bot
Copy link
Contributor

gradio-pr-bot commented Nov 19, 2023

🪼 branch checks and previews

Name Status URL
Spaces ready! Spaces preview
Website ready! Website preview
Storybook ready! Storybook preview
Visual tests all good! Build review
🦄 Changes detected! Details

Install Gradio from this PR

pip install https://gradio-builds.s3.amazonaws.com/58456569f2c99c23c99cc5121cecfea11d514927/gradio-4.8.0-py3-none-any.whl

Install Gradio Python Client from this PR

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

@gradio-pr-bot
Copy link
Contributor

gradio-pr-bot commented Nov 19, 2023

🦄 change detected

This Pull Request includes changes to the following packages.

Package Version
@gradio/gallery patch
gradio patch
  • Maintainers can select this checkbox to manually select packages to update.

With the following changelog entry.

Fix the download button of the gr.Gallery() component to work

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.

@whitphx whitphx force-pushed the fix-gallery-download-button branch 2 times, most recently from cd257c2 to 87e4b23 Compare November 19, 2023 09:22
if (selected_image == null) {
return;
}
const { url, orig_name } = selected_image;
Copy link
Member Author

@whitphx whitphx Nov 19, 2023

Choose a reason for hiding this comment

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

With the current server-side code, orig_name is never set and the downloaded file name is always "image".
@abidlabs Should Python-side be modified to set orig_name as well? I modified gr.Gallery() so (779aa2c). Plz let me know if it shoudl be reverted.

Copy link
Collaborator

Choose a reason for hiding this comment

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

That's a good fix @whitphx - thanks

@whitphx whitphx force-pushed the fix-gallery-download-button branch 2 times, most recently from 8193a85 to 779aa2c Compare November 19, 2023 10:52
@whitphx whitphx marked this pull request as ready for review November 19, 2023 14:29
@hannahblair
Copy link
Collaborator

hannahblair commented Nov 20, 2023

Hey @whitphx! I've just tested this and the images are downloading as html files 🤔

Ignore the above - I needed to rebuild the FE. So I'm still experiencing some weird behaviour when running the gallery component demo. See this recording:

Kapture 2023-11-20 at 16 28 28

To summarise the above:

The first image downloaded the image as a .jpg, as expected.
The second, third, and fourth images resulted in a CORS error
The final image tried to download this url:

Screenshot 2023-11-20 at 17 30 22

Copy link
Collaborator

@freddyaboulton freddyaboulton left a comment

Choose a reason for hiding this comment

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

Thanks for the fix! Do you mind modifying the 2e2 test (gallery_component_events.spec.ts) to download a file from the gallery and make sure it has the right name?

The video tests show how to download files with playwright, should be something like

	const downloadPromise = page.waitForEvent("download");
	await page.getByLabel("Download").click();
	const download = await downloadPromise;
	await expect(download.suggestedFilename()).toBe(<name>);

@whitphx whitphx force-pushed the fix-gallery-download-button branch 5 times, most recently from e340c1f to e96d7dd Compare November 21, 2023 04:58
@whitphx
Copy link
Member Author

whitphx commented Nov 21, 2023

@hannahblair @freddyaboulton Thank you for the review!

I modified the code

  • restoring the original <a>-tag-based download link which is like other places.
  • instead fixing the Python code of gr.Gallery() so its image URL resolution works like gr.Image and the same-origin URL is always passed to the frontend.

Then the CORS problem should be solved and updating the E2E test became unnecessary.
Please take a look again, thanks.

@whitphx whitphx force-pushed the fix-gallery-download-button branch 2 times, most recently from 378f930 to dcac42b Compare November 21, 2023 05:05
@whitphx whitphx force-pushed the fix-gallery-download-button branch 5 times, most recently from 9acc972 to f8fb748 Compare November 21, 2023 07:01
else:
raise ValueError(f"Cannot process type as image: {type(img)}")
entry = GalleryImage(
image=FileData(path=file_path, url=url), caption=caption
# Leave `url` as None so it will be replaced with a local cache path during postprocessing (https://github.com/gradio-app/gradio/blob/c5ea13bdf7363224863760e53fbcdbed81754628/gradio/blocks.py#L1421)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will introduce a regression in performance when compared to main.

You can check with the gallery_component_events demo. The postprocess will take several seconds as opposed to < 1 second.

This change

gallery_postprocess_pr

Main

gallery_postprocess_main

In the past, people have used gr.Gallery to store many image URLs so I'm worried about degrading the experience for them.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's an important point, thanks.
I understand gr.Gallery() is not just a group of gr.Images() but the quantity matters.
So I'm gonna go back to the previous path and improve it.

@whitphx whitphx force-pushed the fix-gallery-download-button branch 2 times, most recently from e718b95 to d403fab Compare November 22, 2023 03:21
@abidlabs
Copy link
Member

abidlabs commented Dec 9, 2023

Awesome PR, thanks for this nice bug fix @whitphx! Left a couple of very minor points above

whitphx and others added 6 commits December 9, 2023 13:57
Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
@whitphx
Copy link
Member Author

whitphx commented Dec 9, 2023

The suggested type syntax didn't work.
I think this is because from __future__ import annotations postpones the evaluations of annotations only, but does nothing about other things such as variable assignments which is used for type aliasing.

Ref:

@whitphx
Copy link
Member Author

whitphx commented Dec 9, 2023

The failed test is only the flaky one. Will merge this ignoring it.

@whitphx whitphx merged commit 9a5811d into main Dec 9, 2023
14 of 15 checks passed
@whitphx whitphx deleted the fix-gallery-download-button branch December 9, 2023 16:58
@pngwn pngwn mentioned this pull request Dec 9, 2023
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.

The download button on gr.Gallery() doesn't work
5 participants