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

Create Warning, Info modals #4518

Merged
merged 40 commits into from Jul 3, 2023
Merged

Create Warning, Info modals #4518

merged 40 commits into from Jul 3, 2023

Conversation

aliabid94
Copy link
Collaborator

Introduce gr.Warning and gr.Info, which can be written anywhere in a function and will cause a Modal to pop up instantly. Requires websockets.

Example code:

import gradio as gr
import time

def greet(name):
    gr.Info("Starting...")
    time.sleep(2)
    if len(name) < 3:
        gr.Warning("Name is short")
    time.sleep(2)
    raise gr.Error("Error!")

demo = gr.Interface(fn=greet, inputs="text", outputs="text")
demo.queue().launch() 

Did not try to capture every warnings.warn that was raised, as it would be quite tricky (having to hijack the warnings library just as we did with tqdm) and I don't think there would be many use cases.

The modal looks the same for Error, Info, and Warning - @hannahblair would you like to take on styling those as well?

@gradio-pr-bot
Copy link
Contributor

All the demos for this PR have been deployed at https://huggingface.co/spaces/gradio-pr-deploys/pr-4518-all-demos

gradio/queueing.py Outdated Show resolved Hide resolved
gradio/blocks.py Outdated Show resolved Hide resolved
gradio/exceptions.py Outdated Show resolved Hide resolved
@hannahblair
Copy link
Collaborator

The modal looks the same for Error, Info, and Warning - @hannahblair would you like to take on styling those as well?

Absolutely. Already on it 😊

@gradio-pr-bot
Copy link
Contributor

The demo notebooks don't match the run.py files. Please run this command from the root of the repo and then commit the changes:

pip install nbformat && cd demo && python generate_notebooks.py

@abidlabs
Copy link
Member

abidlabs commented Jun 15, 2023

Nice @aliabid94! I'm still doing some testing, but I noticed that if there's a gr.Warning raised shortly before the function ends, it does not appear. Here's an example:

import gradio as gr
import time

def test(x):
    gr.Warning("step 1")
    yield "step 1"
    time.sleep(1)
    gr.Warning("step 2")
    yield "step 2"
    time.sleep(1)
    gr.Warning("done")
    # time.sleep(1) # If you uncomment this line, it works 
    yield "done"

gr.Interface(test, "textbox", "textbox").queue().launch()

Speaking of, it would be good to write some tests

gradio/queueing.py Outdated Show resolved Hide resolved
gradio/blocks.py Outdated Show resolved Hide resolved
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.

Apart from one small comment, I'm happy with the frontend code so far. When we're happy with the core implementation, I guess @hannahblair will take over to add the new UI.

client/js/src/client.ts Show resolved Hide resolved
js/app/src/Blocks.svelte Outdated Show resolved Hide resolved
* create abstract toast component for info/warning/error

* add icons

* add light mode theming

* add theme mode check and dark mode styles

* update theme_mode on update

* clean up render of toast content

* replace dynamic css vars with toast type css selectors

* tweak colours

* change error pill border colour to align with toasts

* formatting

* fix failed test

* rename icon files and clean up css
@aliabid94 aliabid94 marked this pull request as ready for review June 30, 2023 05:53
@aliabid94
Copy link
Collaborator Author

ready for re-review

@aliabid94 aliabid94 mentioned this pull request Jun 30, 2023
CHANGELOG.md Show resolved Hide resolved
gradio/helpers.py Outdated Show resolved Hide resolved
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.

Reviewed the frontend code a few times now, and looks good to me! Thanks @hannahblair and @aliabid94!

gradio/helpers.py Outdated Show resolved Hide resolved
@gradio-pr-bot
Copy link
Contributor

gradio-pr-bot commented Jul 3, 2023

Chromatic build successful 🎉

@aliabid94 aliabid94 merged commit 6c54272 into main Jul 3, 2023
12 checks passed
@aliabid94 aliabid94 deleted the info_modal branch July 3, 2023 21:28
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.

None yet

7 participants