-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
gr.Number() max/min limit #3991
Conversation
* feat: add min max handling for Number * Update CHANGELOG.md * fix: Error when min or max is not specified * fix formatting * fix: error when nothing is specified * Just put infinity in min and max --------- Co-authored-by: Dawood Khan <[email protected]>
🎉 The demo notebooks match the run.py files! 🎉 |
All the demos for this PR have been deployed at https://huggingface.co/spaces/gradio-pr-deploys/pr-3991-all-demos |
Very cool @dawoodkhan82! This is the first time we're doing any sort of validation in the frontend, so cc @pngwn @aliabid94 @gary149 on the design piece. |
Co-authored-by: Abubakar Abid <[email protected]>
I tested this code: import gradio as gr
gr.Interface(lambda x:x, gr.Number(min=10, max=20), gr.Number(min=15, max=25)).launch() and on the default theme, it looks and works great: However, on all of the other themes, I don't see any validation error bar: import gradio as gr
gr.Interface(lambda x:x, gr.Number(min=10, max=20), gr.Number(min=15, max=25), theme="monochrome").launch() |
Wouldn't it be better if all input was red instead of borders? It would look more noticeable and most likely be displayed in all themes. |
I think the border turning red like how @dawoodkhan82 has implemented it is more common, from what I've seen, e.g. see the examples here: https://www.nngroup.com/articles/errors-forms-design-guidelines/ |
Okay, I changed my mind. |
So if a user submits a number out of range, it gets clamped in the backend? That might be a bit "magical", a user might think the function ran on what they entered rather than the clamped value. Proposal that may be out of the scope of this: I think we need to allow blocking an event trigger if an input component has an invalid input. Another use-case might be an
If an event tries to trigger with an empty |
Ohh good point @aliabid94. Maybe we raise a
Yup this would be handy also to block the Submit button while a file is uploading, but out of scope of this PR for sure |
Maybe then it would be better to limit the number in the frontend, too, so that the user can't add a number that is out of bounds. When the number changes, check it and limit it if necessary. |
Can we do the same for |
Let's get this merged in @dawoodkhan82. For now, the only change that needs to be made is that we should raise a Later on, we can implement @aliabid94's suggestion, which is to block the submit button altogether cc @hannahblair if you have any suggestions on validation of the |
* [create-pull-request] automated change * Trigger Build --------- Co-authored-by: aliabd <[email protected]> Co-authored-by: aliabd <[email protected]>
…nSaver`) (#3973) * Draft for a safer HuggingFaceDatasetSaver * Rename (and replace) gr.SaferHuggingFaceDatasetSaver as gr.HuggingFaceDatasetSaver * update changelog * ruff * doc * tmp work * merge 2 classes * remove useless code * adapt tests * Update gradio/flagging.py Co-authored-by: Abubakar Abid <[email protected]> * Update CHANGELOG.md * fix typing * code formatting * removed print from tests * removing imports * removing imports * fix paths * formatting * wording * formating * fix tests --------- Co-authored-by: testbot <[email protected]> Co-authored-by: Abubakar Abid <[email protected]>
* state render * add test * formatting * changelog
* allow decoding b64 string without headers * install gradio-client in edittable mode * update GH actions * add test for decoding headerless b64 * add test for decoding headerless b64 image * some linting * fix test --------- Co-authored-by: Abubakar Abid <[email protected]>
* matplotlib-agg * fix * context manager * Update CHANGELOG.md * update demos * linting * removed warning * fix test * fixes * fix tests
* fastapi guide * changelog * writing * finish guide * fix * Update guides/06_client-libraries/fastapi-app-with-the-gradio-client.md Co-authored-by: Ali Abdalla <[email protected]> * Update guides/06_client-libraries/fastapi-app-with-the-gradio-client.md Co-authored-by: Ali Abdalla <[email protected]> * Update guides/06_client-libraries/fastapi-app-with-the-gradio-client.md Co-authored-by: Ali Abdalla <[email protected]> * Update guides/06_client-libraries/fastapi-app-with-the-gradio-client.md Co-authored-by: Ali Abdalla <[email protected]> * dependencies * html --------- Co-authored-by: Ali Abdalla <[email protected]>
* first pass * fixes * more fixes * remove breaks * format * version * pr fixes * changelog * test fix * background color * format * revert test fix * changes * changes * test * changes * changes * changes * changes * changes --------- Co-authored-by: Abubakar Abid <[email protected]> Co-authored-by: Ali Abid <[email protected]>
* Increase version gradio-client version/changelog * req --------- Co-authored-by: Abubakar Abid <[email protected]>
In Slider, we've called the arguments |
How are there 177 commits in this PR..? |
Description
Building off of artegoser PR (which is merged into this branch). Adding frontend support for min/max of
gr.Number()
component.As of now, the border color for the input turns red when a number out of range is typed in.
Please include:
Closes: #934
Checklist:
A note about the CHANGELOG
Hello 👋 and thank you for contributing to Gradio!
All pull requests must update the change log located in CHANGELOG.md, unless the pull request is labeled with the "no-changelog-update" label.
Please add a brief summary of the change to the Upcoming Release > Full Changelog section of the CHANGELOG.md file and include
a link to the PR (formatted in markdown) and a link to your github profile (if you like). For example, "* Added a cool new feature by
[@myusername](link-to-your-github-profile)
in[PR 11111](https://github.com/gradio-app/gradio/pull/11111)
".If you would like to elaborate on your change further, feel free to include a longer explanation in the other sections.
If you would like an image/gif/video showcasing your feature, it may be best to edit the CHANGELOG file using the
GitHub web UI since that lets you upload files directly via drag-and-drop.