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 show_heading param to gr.Label #9987

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open

Conversation

hannahblair
Copy link
Collaborator

@hannahblair hannahblair commented Nov 18, 2024

Description

Adds a show_heading param to gr.Label to allow hiding a the large heading in gr.Labels with multiple labels. show_heading will be void in components with just one label.

Closes: #9975

🎯 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.

Testing and Formatting Your Code

  1. PRs will only be merged if tests pass on CI. We recommend at least running the backend tests locally, please set up your Gradio environment locally and run the backed tests: bash scripts/run_backend_tests.sh

  2. Please run these bash scripts to automatically format your code: bash scripts/format_backend.sh, and (if you made any changes to non-Python files) bash scripts/format_frontend.sh

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Nov 18, 2024

🪼 branch checks and previews

Name Status URL
Spaces ready! Spaces preview
Website ready! Website preview
Storybook ready! Storybook preview
🦄 Changes detecting...

Install Gradio from this PR

pip install https://gradio-pypi-previews.s3.amazonaws.com/44574cc4c01a9d4cd8f26c2e4bb0d935e8b2c3d6/gradio-5.6.0-py3-none-any.whl

Install Gradio Python Client from this PR

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

Install Gradio JS Client from this PR

npm install https://gradio-npm-previews.s3.amazonaws.com/44574cc4c01a9d4cd8f26c2e4bb0d935e8b2c3d6/gradio-client-1.8.0.tgz

Use Lite from this PR

<script type="module" src="https://gradio-lite-previews.s3.amazonaws.com/44574cc4c01a9d4cd8f26c2e4bb0d935e8b2c3d6/dist/lite.js""></script>

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Nov 18, 2024

🦄 change detected

This Pull Request includes changes to the following packages.

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

With the following changelog entry.

Add show_heading param to gr.Label

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 changed the title Add hide_heading param to gr.Label() Add hide_heading param to gr.Label Nov 18, 2024
@abidlabs
Copy link
Member

Why do we ignore the value of hide_heading if its only a single class?

image

This behavior is not intuitive to me^ -- I would have expected hide_heading to still take effect and a single bar to show up

@abidlabs
Copy link
Member

I misunderstood earlier, but I think it would be clearer if if the docstring said something like:

If True, the heading will not be displayed if a dictionary of labels and confidences is provided. The heading will still be visible if the value is a string. Defaults to False

also nit, but I think we usually use show_xxx for all of our parameter names, so for consistency, could we do show_heading: bool = True?

@hannahblair hannahblair changed the title Add hide_heading param to gr.Label Add show_heading param to gr.Label Nov 20, 2024
js/label/Index.svelte Outdated Show resolved Hide resolved
@hannahblair
Copy link
Collaborator Author

lol that was a very arrogant find and replace on my part. thanks @abidlabs, changes made

@abidlabs
Copy link
Member

Hey @hannahblair code changes look good now, but when I test this, e.g. with:

import gradio as gr

with gr.Blocks() as demo:
    gr.Label({"cat": 0.7, "dog": 0.3}, show_heading=False)

demo.launch()

I notice two issues:

(1) The component label is overlapping the topmost category:

image

(2) I don't think this is due to this PR, but you'll notice that the bar has an unusual green color fill inside the orange outline. It looks like the bar width (i.e. the width of the orange outline) is CONFIDENCE% is of the full component width and the green fill is CONFIDENCE% of the bar width. The fill should take up the entire bar width and imo the fill should be the same color as the outline (primary hue)

@umarbutler
Copy link

umarbutler commented Nov 24, 2024

Hey @hannahblair code changes look good now, but when I test this, e.g. with:

import gradio as gr

with gr.Blocks() as demo:
    gr.Label({"cat": 0.7, "dog": 0.3}, show_heading=False)

demo.launch()

I notice two issues:

(1) The component label is overlapping the topmost category:

image (2) I don't think this is due to this PR, but you'll notice that the bar has an unusual green color fill inside the orange outline. It looks like the bar width (i.e. the width of the orange outline) is CONFIDENCE% is of the full component width and the green fill is CONFIDENCE% of the bar width. The fill should take up the entire bar width and imo the fill should be the same color as the outline (primary hue)

I ran into this when trying to use uBlock Origin to hide the header for demo purposes. The only way to make it look good was instead to replace the text in the <h2> tag or whatever it is with nothing (eg, <h2></h2>).

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.

It isn't possible to disable the heading of a Label
4 participants