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

Allow empty value in gr.Number #8974

Closed
wants to merge 12 commits into from
Closed

Allow empty value in gr.Number #8974

wants to merge 12 commits into from

Conversation

hannahblair
Copy link
Collaborator

@hannahblair hannahblair commented Aug 2, 2024

Description

We should allow empty values to be shown on the frontend in gr.Number when its None/null. I've not changed the data type of value itself but rather created a new variable which is used for displaying the value as a empty string when the value is null, and it updates whenever value updates.

Demo:

import gradio as gr

with gr.Blocks() as demo:
    gr.Number(value=None)

demo.launch()

Closes: #6728

🎯 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 Aug 2, 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-builds.s3.amazonaws.com/4671c89b14fb3012a13b92802019e60a368e2960/gradio-4.40.0-py3-none-any.whl

Install Gradio Python Client from this PR

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

Install Gradio JS Client from this PR

npm install https://gradio-builds.s3.amazonaws.com/4671c89b14fb3012a13b92802019e60a368e2960/gradio-client-1.4.0.tgz

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Aug 2, 2024

🦄 change detected

This Pull Request includes changes to the following packages.

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

With the following changelog entry.

Allow empty value in gr.Number

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
Copy link
Collaborator Author

Tests failing, will change implementation

@abidlabs abidlabs marked this pull request as draft August 2, 2024 18:40
@hannahblair hannahblair marked this pull request as ready for review August 4, 2024 19:42
@abidlabs abidlabs self-requested a review August 5, 2024 18:45
Comment on lines +124 to +131

if self.minimum is not None and payload < self.minimum:
raise Error(f"Value {payload} is less than minimum value {self.minimum}.")
elif self.maximum is not None and payload > self.maximum:
raise Error(
f"Value {payload} is greater than maximum value {self.maximum}."
)

Copy link
Member

Choose a reason for hiding this comment

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

IIUC this change should have no effect since the first branch terminates in a return statement, am I misunderstanding?

@@ -96,7 +102,7 @@
border: var(--input-border-width) solid var(--input-border-color);
border-radius: var(--input-radius);
}
input[type="number"] {
input[type="text"] {
Copy link
Member

Choose a reason for hiding this comment

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

This means that browsers won't treat this field as numeric. On Desktop it means we'll lose these:

image

On mobile, I think it will lead to a ux degradation since the numeric keyboard won't pop up anymore

Copy link
Member

Choose a reason for hiding this comment

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

I don't think this change should be needed since at least according to the original issue, it is in theory possible to set a numeric field blank:

Currently, I can set the value to Callable, where Callable returns None. I have tested this, and the frontend displays it as blank, which aligns with my requirements.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This means that browsers won't treat this field as numeric. On Desktop it means we'll lose these:

Thats a good point, we don't want to lose that :/

@hannahblair
Copy link
Collaborator Author

In light of your comment I'll close the issue in which case. Thanks for reviewing nonetheless!

@hannahblair hannahblair closed this Aug 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants