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

Add placeholder param to Image and ImageEditor to replace upload image text #8930

Merged
merged 48 commits into from
Aug 20, 2024

Conversation

hannahblair
Copy link
Collaborator

@hannahblair hannahblair commented Jul 29, 2024

Description

Adds the option to add a placeholder parameter to the image components, to allow replacing the upload text on the upload area.

Screenshot 2024-08-20 at 12 35 54

Closes: #3511

🎯 PRs Should Target Issues

Before your create a PR, please check to see if there is an existing issue for this change. If not, please create an issue before you create this PR, unless the fix is very small.

Not adhering to this guideline will result in the PR being closed.

Tests

  1. PRs will only be merged if tests pass on CI. To run the tests locally, please set up your Gradio environment locally and run the tests: bash scripts/run_all_tests.sh

  2. You may need to run the linters: bash scripts/format_backend.sh and bash scripts/format_frontend.sh

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Jul 29, 2024

🪼 branch checks and previews

Name Status URL
Spaces ready! Spaces preview
Website ready! Website preview
Storybook ready! Storybook preview
🦄 Changes detected! Details

Install Gradio from this PR

pip install https://gradio-pypi-previews.s3.amazonaws.com/4cbd45192a6f8d70f953de3fd355f1ec278bbbb8/gradio-4.41.0-py3-none-any.whl

Install Gradio Python Client from this PR

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

Install Gradio JS Client from this PR

npm install https://gradio-npm-previews.s3.amazonaws.com/4cbd45192a6f8d70f953de3fd355f1ec278bbbb8/gradio-client-1.5.0.tgz

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Jul 29, 2024

🦄 change detected

This Pull Request includes changes to the following packages.

Package Version
@gradio/atoms minor
@gradio/image minor
@gradio/imageeditor minor
@gradio/simpleimage minor
gradio minor
  • Maintainers can select this checkbox to manually select packages to update.

With the following changelog entry.

Add placeholder param to Image and ImageEditor to replace upload image text

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.

@hannahblair hannahblair marked this pull request as ready for review August 5, 2024 14:34
@freddyaboulton
Copy link
Collaborator

freddyaboulton commented Aug 5, 2024

@hannahblair the functionality looks good but two comments:

  • I think the text is a bit hard to read against the gray background
Screenshot 2024-08-05 at 12 53 35 PM
  • Should the title be within the block so that it gets covered by the status tracker like for the other form components (Number, Info)

@hannahblair
Copy link
Collaborator Author

Yeah you're right. I'll make some changes!

@hannahblair hannahblair marked this pull request as draft August 6, 2024 13:28
@hannahblair
Copy link
Collaborator Author

I think I've found a nice solution. Let me know any thoughts here!

Screenshot 2024-08-13 at 13 14 01 Screenshot 2024-08-13 at 13 19 51

@hannahblair hannahblair marked this pull request as ready for review August 13, 2024 11:21
@hannahblair
Copy link
Collaborator Author

there's a slight px difference in the chromatic tests so i'll fix that

@aliabid94
Copy link
Collaborator

I like the second design but now it covers up too much of the image I feel.

@abidlabs
Copy link
Member

Thanks @hannahblair! I tested this out, and I'm seeing:

  1. as mentioned above, arbitrary HTML/JS can be injected because we don't sanitize the HTML prior to rendering.
  2. Support for headings isn't working for me, not sure why. Am I testing it wrong?
image

@@ -292,7 +319,7 @@
align-items: center;
color: var(--block-label-text-color);
line-height: var(--line-md);
font-size: var(--text-lg);
font-size: var(--text-md);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

tweaked to be consistent with gr.Image

const _paragraph = remaining_text || false;

return [_heading, _paragraph];
}
Copy link
Collaborator Author

@hannahblair hannahblair Aug 20, 2024

Choose a reason for hiding this comment

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

@pngwn tweaked this to accommodate headings on new lines - also a general note this only extracts the first heading, which I think is fine

Copy link
Member

@pngwn pngwn left a comment

Choose a reason for hiding this comment

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

Small comment but looks good and works great! Thanks for taking care of this @hannahblair!

js/atoms/src/UploadText.svelte Outdated Show resolved Hide resolved
@abidlabs
Copy link
Member

Nice @hannahblair. I noticed a couple of things with the heading:

(1) If the placeholder is only a heading, it will repeat twice, like this:

image

(2) The difference between the heading font size and the regular text in gr.Image is not that noticeable. For ImageEditor, the differences are more noticeable:

image image

Nit: although even for gr.ImageEditor, they both look rather small. I would have expected the size of the regular placeholder text to the around the current size for the heading, and the heading to be slightly larger. (This is just personal preference so feel free to ignore)

@pngwn
Copy link
Member

pngwn commented Aug 20, 2024

Left a comment about the above issue.

@hannahblair
Copy link
Collaborator Author

hannahblair commented Aug 20, 2024

@abidlabs fixed the dupe heading text. wdyt of this heading text size? I've changed them from lg to xl:

Screenshot 2024-08-20 at 22 09 50

@hannahblair
Copy link
Collaborator Author

Screenshot 2024-08-20 at 22 50 44

Confused about why I'm seeing this diff (note the outline) when this is how it looks in main anyway

@abidlabs
Copy link
Member

@abidlabs fixed the dupe heading text. wdyt of this heading text size? I've changed them from lg to xl:

Looks good to me! Let me do another round of testing

@abidlabs
Copy link
Member

I'm seeing headings are not rendered in gr.Image -- they are rendered in gr.ImageEditor:

image

Did you push all of the changes?

Copy link
Member

@abidlabs abidlabs left a comment

Choose a reason for hiding this comment

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

LGTM @hannahblair, thanks for accommodating all of the feedback!

@hannahblair
Copy link
Collaborator Author

LGTM @hannahblair, thanks for accommodating all of the feedback!

@abidlabs Thank you for the patience with the rereviews 😅

@hannahblair hannahblair merged commit 41d5ab9 into main Aug 20, 2024
20 of 21 checks passed
@hannahblair hannahblair deleted the info-image branch August 20, 2024 23:22
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.

Support info with gr.Image
7 participants