gradio-toggle


Namegradio-toggle JSON
Version 0.0.2 PyPI version JSON
download
home_page
SummaryA custom component that toggles between on and off states. Ideal for intuitive user controls and dynamic input handling in machine learning models and data presentations.
upload_time2024-03-04 05:41:45
maintainer
docs_urlNone
authorDaniel Ialcin Misser Westergaard
requires_python>=3.8
license
keywords button checkbox gradio-custom-component gradio-template-checkbox select toggle
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# `gradio_toggle`
<a href="https://pypi.org/project/gradio_toggle/" target="_blank"><img alt="PyPI - Version" src="https://img.shields.io/pypi/v/gradio_toggle"></a>  

A custom component that toggles between on and off states. Ideal for intuitive user controls and dynamic input handling in machine learning models and data presentations.

## Installation

```bash
pip install gradio_toggle
```

## Usage

```python

import gradio as gr
from gradio_toggle import Toggle

toggle_value = False
toggle_message = ""

def toggle_action(toggle_value):
    if toggle_value == False:
        toggle_message = "Toggle is False 👎"
    elif toggle_value == True:
        toggle_message = "Toggle is True 👍"
    else:
        toggle_message = "Error 😢"
    
    return toggle_message

with gr.Blocks() as demo:
    with gr.Row():
        with gr.Column():
            input = Toggle(label="Input", value=toggle_value, show_label=True, info="This is a toggle button.")
        with gr.Column():
            output = gr.Label(label="Output")
    
    input.change(fn=toggle_action, inputs=input, outputs=output)

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

```

## `Toggle`

### Initialization

<table>
<thead>
<tr>
<th align="left">name</th>
<th align="left" style="width: 25%;">type</th>
<th align="left">default</th>
<th align="left">description</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left"><code>value</code></td>
<td align="left" style="width: 25%;">

```python
bool | Callable
```

</td>
<td align="left"><code>False</code></td>
<td align="left">Initial state of the toggle. If a callable is provided, it sets the initial state dynamically.</td>
</tr>

<tr>
<td align="left"><code>label</code></td>
<td align="left" style="width: 25%;">

```python
str | None
```

</td>
<td align="left"><code>None</code></td>
<td align="left">Text label displayed adjacent to the toggle. Useful for providing context.</td>
</tr>

<tr>
<td align="left"><code>info</code></td>
<td align="left" style="width: 25%;">

```python
str | None
```

</td>
<td align="left"><code>None</code></td>
<td align="left">Additional information or instructions displayed below the toggle.</td>
</tr>

<tr>
<td align="left"><code>every</code></td>
<td align="left" style="width: 25%;">

```python
float | None
```

</td>
<td align="left"><code>None</code></td>
<td align="left">If value is a callable, this defines how often (in seconds) to refresh the toggle's state.</td>
</tr>

<tr>
<td align="left"><code>show_label</code></td>
<td align="left" style="width: 25%;">

```python
bool | None
```

</td>
<td align="left"><code>None</code></td>
<td align="left">Controls the visibility of the label.</td>
</tr>

<tr>
<td align="left"><code>container</code></td>
<td align="left" style="width: 25%;">

```python
bool
```

</td>
<td align="left"><code>True</code></td>
<td align="left">None</td>
</tr>

<tr>
<td align="left"><code>scale</code></td>
<td align="left" style="width: 25%;">

```python
int | None
```

</td>
<td align="left"><code>None</code></td>
<td align="left">Adjusts the size of the toggle relative to adjacent components.</td>
</tr>

<tr>
<td align="left"><code>min_width</code></td>
<td align="left" style="width: 25%;">

```python
int
```

</td>
<td align="left"><code>75</code></td>
<td align="left">Minimum width of the toggle in pixels. Ensures readability and usability.</td>
</tr>

<tr>
<td align="left"><code>interactive</code></td>
<td align="left" style="width: 25%;">

```python
bool | None
```

</td>
<td align="left"><code>None</code></td>
<td align="left">Enables or disables user interaction with the toggle.</td>
</tr>

<tr>
<td align="left"><code>visible</code></td>
<td align="left" style="width: 25%;">

```python
bool
```

</td>
<td align="left"><code>True</code></td>
<td align="left">Controls the visibility of the toggle on the interface.</td>
</tr>

<tr>
<td align="left"><code>elem_id</code></td>
<td align="left" style="width: 25%;">

```python
str | None
```

</td>
<td align="left"><code>None</code></td>
<td align="left">An optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles.</td>
</tr>

<tr>
<td align="left"><code>elem_classes</code></td>
<td align="left" style="width: 25%;">

```python
list[str] | str | None
```

</td>
<td align="left"><code>None</code></td>
<td align="left">An optional list of strings that are assigned as the classes of this component in the HTML DOM. Can be used for targeting CSS styles.</td>
</tr>

<tr>
<td align="left"><code>render</code></td>
<td align="left" style="width: 25%;">

```python
bool
```

</td>
<td align="left"><code>True</code></td>
<td align="left">Determines if the toggle is rendered immediately in the Blocks context.</td>
</tr>
</tbody></table>


### 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, passes the status of the checkbox as a `bool`.
- **As input:** Should return, expects a `bool` value that is set as the status of the toggle.

 ```python
 def predict(
     value: bool | None
 ) -> bool | None:
     return value
 ```
 

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "gradio-toggle",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "button,checkbox,gradio-custom-component,gradio-template-Checkbox,select,toggle",
    "author": "Daniel Ialcin Misser Westergaard",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/c6/95/6ef40a8111cd1e0d1d71cf918f0a490d748701b1e2fb3f8fe73936f6b2f6/gradio_toggle-0.0.2.tar.gz",
    "platform": null,
    "description": "\n# `gradio_toggle`\n<a href=\"https://pypi.org/project/gradio_toggle/\" target=\"_blank\"><img alt=\"PyPI - Version\" src=\"https://img.shields.io/pypi/v/gradio_toggle\"></a>  \n\nA custom component that toggles between on and off states. Ideal for intuitive user controls and dynamic input handling in machine learning models and data presentations.\n\n## Installation\n\n```bash\npip install gradio_toggle\n```\n\n## Usage\n\n```python\n\nimport gradio as gr\nfrom gradio_toggle import Toggle\n\ntoggle_value = False\ntoggle_message = \"\"\n\ndef toggle_action(toggle_value):\n    if toggle_value == False:\n        toggle_message = \"Toggle is False \ud83d\udc4e\"\n    elif toggle_value == True:\n        toggle_message = \"Toggle is True \ud83d\udc4d\"\n    else:\n        toggle_message = \"Error \ud83d\ude22\"\n    \n    return toggle_message\n\nwith gr.Blocks() as demo:\n    with gr.Row():\n        with gr.Column():\n            input = Toggle(label=\"Input\", value=toggle_value, show_label=True, info=\"This is a toggle button.\")\n        with gr.Column():\n            output = gr.Label(label=\"Output\")\n    \n    input.change(fn=toggle_action, inputs=input, outputs=output)\n\nif __name__ == \"__main__\":\n    demo.launch()\n\n```\n\n## `Toggle`\n\n### Initialization\n\n<table>\n<thead>\n<tr>\n<th align=\"left\">name</th>\n<th align=\"left\" style=\"width: 25%;\">type</th>\n<th align=\"left\">default</th>\n<th align=\"left\">description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td align=\"left\"><code>value</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nbool | Callable\n```\n\n</td>\n<td align=\"left\"><code>False</code></td>\n<td align=\"left\">Initial state of the toggle. If a callable is provided, it sets the initial state dynamically.</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>label</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nstr | None\n```\n\n</td>\n<td align=\"left\"><code>None</code></td>\n<td align=\"left\">Text label displayed adjacent to the toggle. Useful for providing context.</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>info</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nstr | None\n```\n\n</td>\n<td align=\"left\"><code>None</code></td>\n<td align=\"left\">Additional information or instructions displayed below the toggle.</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>every</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nfloat | None\n```\n\n</td>\n<td align=\"left\"><code>None</code></td>\n<td align=\"left\">If value is a callable, this defines how often (in seconds) to refresh the toggle's state.</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>show_label</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nbool | None\n```\n\n</td>\n<td align=\"left\"><code>None</code></td>\n<td align=\"left\">Controls the visibility of the label.</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>container</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nbool\n```\n\n</td>\n<td align=\"left\"><code>True</code></td>\n<td align=\"left\">None</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>scale</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nint | None\n```\n\n</td>\n<td align=\"left\"><code>None</code></td>\n<td align=\"left\">Adjusts the size of the toggle relative to adjacent components.</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>min_width</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nint\n```\n\n</td>\n<td align=\"left\"><code>75</code></td>\n<td align=\"left\">Minimum width of the toggle in pixels. Ensures readability and usability.</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>interactive</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nbool | None\n```\n\n</td>\n<td align=\"left\"><code>None</code></td>\n<td align=\"left\">Enables or disables user interaction with the toggle.</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>visible</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nbool\n```\n\n</td>\n<td align=\"left\"><code>True</code></td>\n<td align=\"left\">Controls the visibility of the toggle on the interface.</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>elem_id</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nstr | None\n```\n\n</td>\n<td align=\"left\"><code>None</code></td>\n<td align=\"left\">An optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles.</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>elem_classes</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nlist[str] | str | None\n```\n\n</td>\n<td align=\"left\"><code>None</code></td>\n<td align=\"left\">An optional list of strings that are assigned as the classes of this component in the HTML DOM. Can be used for targeting CSS styles.</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>render</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nbool\n```\n\n</td>\n<td align=\"left\"><code>True</code></td>\n<td align=\"left\">Determines if the toggle is rendered immediately in the Blocks context.</td>\n</tr>\n</tbody></table>\n\n\n### Events\n\n| name | description |\n|:-----|:------------|\n| `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. |\n| `input` | This listener is triggered when the user changes the value of the Toggle. |\n| `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 |\n\n\n\n### User function\n\nThe impact on the users predict function varies depending on whether the component is used as an input or output for an event (or both).\n\n- When used as an Input, the component only impacts the input signature of the user function.\n- When used as an output, the component only impacts the return signature of the user function.\n\nThe code snippet below is accurate in cases where the component is used as both an input and an output.\n\n- **As output:** Is passed, passes the status of the checkbox as a `bool`.\n- **As input:** Should return, expects a `bool` value that is set as the status of the toggle.\n\n ```python\n def predict(\n     value: bool | None\n ) -> bool | None:\n     return value\n ```\n \n",
    "bugtrack_url": null,
    "license": "",
    "summary": "A custom component that toggles between on and off states. Ideal for intuitive user controls and dynamic input handling in machine learning models and data presentations.",
    "version": "0.0.2",
    "project_urls": null,
    "split_keywords": [
        "button",
        "checkbox",
        "gradio-custom-component",
        "gradio-template-checkbox",
        "select",
        "toggle"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a3dc4fe098704ed0897c6c3417f4a1bd4b897e47dd92ead01ffd6fee3bac6f9e",
                "md5": "e5983d699882ebcf5c8020e63c25ee20",
                "sha256": "4f02bc25fb1dba86f697e2b199c573c3959e8894b4d32ef32dac8891bda848eb"
            },
            "downloads": -1,
            "filename": "gradio_toggle-0.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e5983d699882ebcf5c8020e63c25ee20",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 28086,
            "upload_time": "2024-03-04T05:41:44",
            "upload_time_iso_8601": "2024-03-04T05:41:44.182633Z",
            "url": "https://files.pythonhosted.org/packages/a3/dc/4fe098704ed0897c6c3417f4a1bd4b897e47dd92ead01ffd6fee3bac6f9e/gradio_toggle-0.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c6956ef40a8111cd1e0d1d71cf918f0a490d748701b1e2fb3f8fe73936f6b2f6",
                "md5": "829c7166406fbb4ed6b7da1fccf67c9a",
                "sha256": "d8e511d2a2c54d497211a6c5ad1f4d449c503fcd3813ea1dd07d3f66266081c7"
            },
            "downloads": -1,
            "filename": "gradio_toggle-0.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "829c7166406fbb4ed6b7da1fccf67c9a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 41177,
            "upload_time": "2024-03-04T05:41:45",
            "upload_time_iso_8601": "2024-03-04T05:41:45.587493Z",
            "url": "https://files.pythonhosted.org/packages/c6/95/6ef40a8111cd1e0d1d71cf918f0a490d748701b1e2fb3f8fe73936f6b2f6/gradio_toggle-0.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-04 05:41:45",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "gradio-toggle"
}
        
Elapsed time: 0.20564s