-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Control Display of Error, Info, Warning #8489
Conversation
🪼 branch checks and previews
Install Gradio from this PR pip install https://gradio-builds.s3.amazonaws.com/9688f4d10dc997f877a0feaf94fff10d98c6c9bf/gradio-4.36.1-py3-none-any.whl Install Gradio Python Client from this PR pip install "gradio-client @ git+https://github.com/gradio-app/gradio@9688f4d10dc997f877a0feaf94fff10d98c6c9bf#subdirectory=client/python" Install Gradio JS Client from this PR npm install https://gradio-builds.s3.amazonaws.com/9688f4d10dc997f877a0feaf94fff10d98c6c9bf/gradio-client-1.1.1.tgz |
🦄 change detectedThis Pull Request includes changes to the following packages.
With the following changelog entry.
Maintainers or the PR author can modify the PR title to modify this entry.
|
``` | ||
|
||
<!--- Description --> | ||
### Description | ||
## {@html style_formatted_text(obj.description)} | ||
|
||
## You can control for how long the error message is displayed with the `duration` parameter. If it's `None`, the message will be displayed forever until the user closes it. If it's a number, it will be shown for that many seconds. | ||
|
||
## Below is a demo of how different values of duration control the error, info, and warning messages. You can see the code [here](https://huggingface.co/spaces/freddyaboulton/gradio-error-duration/blob/244331cf53f6b5fa2fd406ece3bf55c6ccb9f5f2/app.py#L17). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aliabd The link here is not being formatted as a link. How can I fix it?

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pushed a commit that fixed it. also styling clash.
what's happening with these issues is that i had overrided some default styling rules to design stuff (for example the side bar is a ul but we don't want bullet points there) and now we need them for the content.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
Btw I think this sufficiently closes #6480
This is complete
I don't think we want to do this, especially the second part as we are planning on instead having a dedicated way to do frontend validation |
gradio/exceptions.py
Outdated
def __init__( | ||
self, | ||
message: str = "Error raised.", | ||
duration: int | None = 10, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit but
duration: int | None = 10, | |
duration: int | float | None = 10, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just float is fine, int is a subset of float
With number values I'm used to |
I think it's just a bit confusing that 0 and None have such different meanings, when they're both "falsy". Wonder if another |
client/js/src/helpers/api_info.ts
Outdated
@@ -318,6 +318,8 @@ export function handle_message( | |||
status: { | |||
queue, | |||
message: data.output.error as string, | |||
display: data.output.display as boolean, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where is display
passed from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Originally had a separate display parameter. Added it back as visible
so this makes more sense now.
gradio/queueing.py
Outdated
@@ -376,6 +381,7 @@ def log_message( | |||
event_id: str, | |||
log: str, | |||
level: Literal["info", "warning"], | |||
duration: int | None = 10000, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why 10000 by default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Originally had it being set in ms and forgot to change the default. Fixed now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a few comments, otherwise LGTM!
Yes that's fair. Originally had a separate |
cf22f48
to
b9dd4a0
Compare
Description
Adds
duration
property togr.Warning
,gr.Info
, andgr.Error
.Setting
duration
to 0 not display the toast in the UI. This is useful for giving useful error messages for clients. For example, the data validation done in the component classes can now raisegr.Error
instead ofTypeError
orValueError
and clients will see the exact error message.The
duration
parameter is specified in seconds. If it'sNone
, the toast will be displayed indefinitely.Closes: #6480
🎯 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
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
You may need to run the linters:
bash scripts/format_backend.sh
andbash scripts/format_frontend.sh