freddyaboulton / gradio-range-slider

Apache License 2.0
5 stars 1 forks source link

Maximum not fail-safe on initial render #2

Closed henryruhs closed 5 months ago

henryruhs commented 5 months ago

It is kinda easy to break the range-slider by having a maximum lower than the value range.

maximum: 100,
value: (0, 270)

image

freddyaboulton commented 5 months ago

Fixed in version 0.0.3.

rangeslider_clamp


import gradio as gr
from gradio_rangeslider import RangeSlider
from pathlib import Path

text = "## The range is: {min} to {max}"

docs = Path(__file__).parent / "docs.md"

with gr.Blocks() as demo:
    with gr.Tabs():
        with gr.Tab("Demo"):
            gr.Markdown("""## 🛝 RangeSlider

            ## Drag either end and see the selected endpoints update in real-time.
            """) 
            range_slider = RangeSlider(minimum=0, maximum=100, value=(0, 500))
            with gr.Row():
                with gr.Column():
                    range_ = gr.Markdown(value=text.format(min=0, max=100))
                with gr.Column():
                    label = gr.JSON(label="Value on release")
            range_slider.change(lambda s: text.format(min=s[0], max=s[1]), range_slider, range_,
                                show_progress="hide", trigger_mode="always_last")
            range_slider.release(lambda s: dict(min=s[0], max=s[1]), range_slider, label)
            button = gr.Button("Break Range")
            button.click(lambda: (-10, 270), None, range_slider)
            gr.Examples([(20, 30), (40, 80)], inputs=[range_slider])
        with gr.Tab("Docs"):
            gr.Markdown(docs.read_text())

if __name__ == "__main__":
    demo.launch()