🛝 Slider component for selecting a range of values
APACHE-2.0 License
gradio_rangeslider
🛝 Slider component for selecting a range of values
pip install gradio_rangeslider
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
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
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. |
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).
The code snippet below is accurate in cases where the component is used as both an input and an output.
def predict(
value: typing.Tuple[float, float][float, float]
) -> typing.Optional[typing.Tuple[float, float]][
typing.Tuple[float, float][float, float], None
]:
return value