gradio_toggle
A custom Gradio component that toggles between on and off states.
Installation
pip install gradio_toggle
Usage
# Toggle - A Gradio Custom Component
# Created by Daniel Ialcin Misser Westergaard
# https://huggingface.co/dwancin
# https://github.com/dwancin
# (c) 2024
import gradio as gr
from gradio_toggle import Toggle
def update_toggle_state(input_component):
print(f"Updating toggle: {input_component}")
return input_component
with gr.Blocks() as demo:
with gr.Row():
with gr.Column():
input_component = Toggle()
with gr.Column():
output_component = Toggle(color="red", info="this is the output", show_label=False, interactive=False, radius="sm", transition=1)
input_component.change(fn=update_toggle_state, inputs=input_component, outputs=output_component)
if __name__ == '__main__':
demo.launch()
Toggle
Initialization
| name | type | default | description |
|---|---|---|---|
value |
bool | Callable
|
False |
|
label |
str | None
|
None |
|
info |
str | None
|
None |
|
color |
str | Callable | None
|
None |
|
radius |
Literal["sm", "lg"]
|
"lg" |
|
transition |
float
|
0.3 |
|
every |
Timer | float | None
|
None |
|
inputs |
Component | Sequence[Component] | set[Component] | None
|
None |
None |
show_label |
bool | None
|
None |
|
container |
bool
|
True |
|
scale |
int | None
|
None |
|
min_width |
int
|
160 |
|
interactive |
bool | None
|
None |
|
visible |
bool
|
True |
|
elem_id |
str | None
|
None |
|
elem_classes |
list[str] | str | None
|
None |
|
render |
bool
|
True |
|
key |
int | str | None
|
None |
Events
| name | description |
|---|---|
change |
Triggered when the value of the Toggle 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 Toggle. |
select |
Event listener for when the user selects or deselects the Toggle. Uses event data gradio.SelectData to carry value referring to the label of the Toggle, and selected to refer to state of the Toggle. See EventData documentation on how to use this event data |
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, the toggle state as a boolean value.
- As input: Should return, the toggle state to be returned.
def predict(
value: bool | None
) -> bool | None:
return value
Metadata
Release files for gradio-toggle 2.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| gradio_toggle-2.0.2.tar.gz | 1.2 MB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| gradio_toggle-2.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 2.3 MB
Release files / gradio_toggle-2.0.2.tar.gz
| Download URL | gradio_toggle-2.0.2.tar.gz |
|---|---|
| Size | 1.2 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d6491486749e3cde6779142a15f608ef2fee17f9d05e10ea8942bf6f36954284
|
|
BLAKE2b-256 checksum How to use checksums |
9994ac6e2a5d099f4fcf1f64093bf1f51c30cca63a9ae34bdb2b15be7787a94e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.3
|
Release files / gradio_toggle-2.0.2-py3-none-any.whl
| Download URL | gradio_toggle-2.0.2-py3-none-any.whl |
|---|---|
| Size | 1.1 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
adaa81d1d861eb0a0e427d287eefa705b296200d8743ddd9db8995c5be174ed3
|
|
BLAKE2b-256 checksum How to use checksums |
5ee6f1c4e614ea764b5481e8539c4edcb7bf432b738f230afeeaa5f008e6b205
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.3
|