gradio-range-slider

🛝 Slider component for selecting a range of values

APACHE-2.0 License

Downloads
169.4K
Stars
3

tags: [gradio-custom-component, Slider, leaderboards, forms, filtering, slider]
title: gradio_rangeslider
short_description: 🛝 Slider component for selecting a range of values
colorFrom: blue
colorTo: yellow
sdk: gradio
pinned: false
app_file: app.py

gradio_rangeslider

🛝 Slider component for selecting a range of values

Installation

pip install gradio_rangeslider

Usage


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, 100))
            range_ = gr.Markdown(value=text.format(min=0, max=100))
            range_slider.change(lambda s: text.format(min=s[0], max=s[1]), range_slider, range_,
                                show_progress="hide", trigger_mode="always_last")
            gr.Slider(label="Normal slider", minimum=0, maximum=100, value=50, interactive=True)
            gr.Examples([(20, 30), (40, 80)], inputs=[range_slider])
        with gr.Tab("Docs"):
            gr.Markdown(docs.read_text())


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

RangeSlider

Initialization

float
float
typing.Union[
    typing.Tuple[float, float], typing.Callable, NoneType
][typing.Tuple[float, float][float, float], Callable, None]
float | None
str | None
str | None
float | None
bool | None
bool
int | None
int
bool | None
bool
str | None
list[str] | str | None
bool

Events

name description
change Triggered when the value of the RangeSlider changes either because of user input (e.g. a user types in a textbox) OR because of a function update (e.g. an image receives a value from the output of an event trigger). See .input() for a listener that is only triggered by user input.
input This listener is triggered when the user changes the value of the RangeSlider.
release This listener is triggered when the user releases the mouse on this RangeSlider.

User function

The impact on the users predict function varies depending on whether the component is used as an input or output for an event (or both).

  • When used as an Input, the component only impacts the input signature of the user function.
  • When used as an output, the component only impacts the return signature of the user function.

The code snippet below is accurate in cases where the component is used as both an input and an output.

  • As output: Is passed, passes slider value as a {float} into the function.
  • As input: Should return, expects an {int} or {float} returned from function and sets slider value to it as long as it is within range (otherwise, sets to minimum value).
def predict(
    value: typing.Tuple[float, float][float, float]
) -> typing.Optional[typing.Tuple[float, float]][
   typing.Tuple[float, float][float, float], None
]:
    return value