1. Modals
  2. Warning

New to Gradio? Start here: Getting Started

See the Release History

To install Gradio from main, run the following command:

pip install https://gradio-builds.s3.amazonaws.com/3fcd23a09df280468351eac4fb081e79c8e58216/gradio-6.0.1-py3-none-any.whl

*Note: Setting share=True in launch() will not work.

Warning

gradio.Warning("A warning occured ⛔️!", duration=5)

Description

This function allows you to pass custom warning messages to the user. You can do so simply by writing gr.Warning('message here') in your function, and when that line is executed the custom message will appear in a modal on the demo. The modal is yellow by default and has the heading: "Warning." Queue must be enabled for this behavior; otherwise, the warning will be printed to the console using the warnings library.

Example Usage

import gradio as gr
def hello_world():
    gr.Warning('This is a warning message.')
    return "hello world"
with gr.Blocks() as demo:
    md = gr.Markdown()
    demo.load(hello_world, inputs=None, outputs=[md])
demo.queue().launch()

Initialization

Parameters
🔗
message: str
default = "Warning issued."

The warning message to be displayed to the user. Can be HTML, which will be rendered in the modal.

🔗
duration: float | None
default = 10

The duration in seconds that the warning message should be displayed for. If None or 0, the message will be displayed indefinitely until the user closes it.

🔗
visible: bool
default = True

Whether the error message should be displayed in the UI.

🔗
title: str
default = "Warning"

The title to be displayed to the user at the top of the modal.

Demos