gradio-imageslider


Namegradio-imageslider JSON
Version 0.0.20 PyPI version JSON
download
home_pageNone
SummaryA Gradio component for comparing two images. This component can be used in several ways: - as a **unified input / output** where users will upload a single image and an inference function will generate an image it can be compared to (see demo), - as a **manual upload input** allowing users to compare two of their own images (which can then be passed along elsewhere, e.g. to a model), - as **static output component** allowing users to compare two images generated by an inference function.
upload_time2024-04-19 14:41:11
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseNone
keywords gradio gradio custom component machine learning reproducibility visualization
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# `gradio_imageslider`
<a href="https://pypi.org/project/gradio_imageslider/" target="_blank"><img alt="PyPI - Version" src="https://img.shields.io/pypi/v/gradio_imageslider"></a> <a href="https://github.com/pngwn/gradio-imageslider/issues" target="_blank"><img alt="Static Badge" src="https://img.shields.io/badge/Issues-white?logo=github&logoColor=black"></a> 

A Gradio component for comparing two images.

This component can be used in several ways:

- as a **unified input / output** where users will upload a single image and an inference function will generate an image it can be compared to (see demo),
- as a **manual upload input** allowing users to compare two of their own images (which can then be passed along elsewhere, e.g. to a model), 
- as **static output component** allowing users to compare two images generated by an inference function.


## Installation

```bash
pip install gradio_imageslider
```

## Usage

```python
import gradio as gr
from gradio_imageslider import ImageSlider
from PIL import ImageFilter


def fn(im):
    if not im or not im[0]:
        return im
    return (im[0], im[0].filter(filter=ImageFilter.GaussianBlur(radius=10)))


with gr.Blocks() as demo:
    with gr.Group():
        img1 = ImageSlider(label="Blur image", type="pil", slider_color="pink")
        img1.upload(fn, inputs=img1, outputs=img1)

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

```

## `ImageSlider`

### 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
tuple[str, str]
    | tuple[PIL.Image.Image, PIL.Image.Image]
    | tuple[numpy.ndarray, numpy.ndarray]
    | None
```

</td>
<td align="left"><code>None</code></td>
<td align="left">A PIL Image, numpy array, path or URL for the default value that Image component is going to take. If callable, the function will be called whenever the app loads to set the initial value of the component.</td>
</tr>

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

```python
int
```

</td>
<td align="left"><code>0.5</code></td>
<td align="left">The position of the slider, between 0 and 1.</td>
</tr>

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

```python
int
```

</td>
<td align="left"><code>1</code></td>
<td align="left">The number of images that can be uploaded to the component. 1 or 2.</td>
</tr>

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

```python
int | None
```

</td>
<td align="left"><code>None</code></td>
<td align="left">Height of the displayed image in pixels.</td>
</tr>

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

```python
int | None
```

</td>
<td align="left"><code>None</code></td>
<td align="left">Width of the displayed image in pixels.</td>
</tr>

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

```python
"numpy" | "pil" | "filepath"
```

</td>
<td align="left"><code>"numpy"</code></td>
<td align="left">The format the image is converted to before being passed into the prediction function. "numpy" converts the image to a numpy array with shape (height, width, 3) and values from 0 to 255, "pil" converts the image to a PIL image object, "filepath" passes a str path to a temporary file containing the image.</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">component name in interface.</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, run the function 'every' number of seconds while the client connection is open. Has no effect otherwise. Queue must be enabled. The event can be accessed (e.g. to cancel it) via this component's .load_event attribute.</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">if True, will display label.</td>
</tr>

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

```python
bool
```

</td>
<td align="left"><code>True</code></td>
<td align="left">If True, will display button to download image.</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">If True, will place the component in a container - providing some extra padding around the border.</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">relative width compared to adjacent Components in a Row. For example, if Component A has scale=2, and Component B has scale=1, A will be twice as wide as B. Should be an integer.</td>
</tr>

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

```python
int
```

</td>
<td align="left"><code>160</code></td>
<td align="left">minimum pixel width, will wrap if not sufficient screen space to satisfy this value. If a certain scale value results in this Component being narrower than min_width, the min_width parameter will be respected first.</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">if True, will allow users to upload and edit an image; if False, can only be used to display images. If not provided, this is inferred based on whether the component is used as an input or output.</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">If False, component will be hidden.</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>show_share_button</code></td>
<td align="left" style="width: 25%;">

```python
bool | None
```

</td>
<td align="left"><code>None</code></td>
<td align="left">If True, will show a share icon in the corner of the component that allows user to share outputs to Hugging Face Spaces Discussions. If False, icon does not appear. If set to None (default behavior), then the icon appears if this Gradio app is launched on Spaces, but not otherwise.</td>
</tr>

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

```python
str | None
```

</td>
<td align="left"><code>None</code></td>
<td align="left">The color of the slider separator.</td>
</tr>
</tbody></table>


### Events

| name | description |
|:-----|:------------|
| `change` | Triggered when the value of the ImageSlider 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. |
| `upload` | This listener is triggered when the user uploads a file into the ImageSlider. |



### 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, tuple of images in the requested format.
- **As input:** Should return, image as a numpy array, PIL Image, string/Path filepath, or string URL.

 ```python
 def predict(
     value: tuple[str, str]
    | tuple[PIL.Image.Image, PIL.Image.Image]
    | tuple[numpy.ndarray, numpy.ndarray]
    | None
 ) -> tuple[str, str]
    | tuple[PIL.Image.Image, PIL.Image.Image]
    | tuple[numpy.ndarray, numpy.ndarray]
    | None:
     return value
 ```
 

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "gradio-imageslider",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "gradio, gradio custom component, machine learning, reproducibility, visualization",
    "author": null,
    "author_email": "pngwn <hello@pngwn.io>",
    "download_url": "https://files.pythonhosted.org/packages/4e/20/aadd2089f4b45abb8f8a407ad124c6a0bda35298bb44af56cc160ec6d945/gradio_imageslider-0.0.20.tar.gz",
    "platform": null,
    "description": "\n# `gradio_imageslider`\n<a href=\"https://pypi.org/project/gradio_imageslider/\" target=\"_blank\"><img alt=\"PyPI - Version\" src=\"https://img.shields.io/pypi/v/gradio_imageslider\"></a> <a href=\"https://github.com/pngwn/gradio-imageslider/issues\" target=\"_blank\"><img alt=\"Static Badge\" src=\"https://img.shields.io/badge/Issues-white?logo=github&logoColor=black\"></a> \n\nA Gradio component for comparing two images.\n\nThis component can be used in several ways:\n\n- as a **unified input / output** where users will upload a single image and an inference function will generate an image it can be compared to (see demo),\n- as a **manual upload input** allowing users to compare two of their own images (which can then be passed along elsewhere, e.g. to a model), \n- as **static output component** allowing users to compare two images generated by an inference function.\n\n\n## Installation\n\n```bash\npip install gradio_imageslider\n```\n\n## Usage\n\n```python\nimport gradio as gr\nfrom gradio_imageslider import ImageSlider\nfrom PIL import ImageFilter\n\n\ndef fn(im):\n    if not im or not im[0]:\n        return im\n    return (im[0], im[0].filter(filter=ImageFilter.GaussianBlur(radius=10)))\n\n\nwith gr.Blocks() as demo:\n    with gr.Group():\n        img1 = ImageSlider(label=\"Blur image\", type=\"pil\", slider_color=\"pink\")\n        img1.upload(fn, inputs=img1, outputs=img1)\n\nif __name__ == \"__main__\":\n    demo.launch()\n\n```\n\n## `ImageSlider`\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\ntuple[str, str]\n    | tuple[PIL.Image.Image, PIL.Image.Image]\n    | tuple[numpy.ndarray, numpy.ndarray]\n    | None\n```\n\n</td>\n<td align=\"left\"><code>None</code></td>\n<td align=\"left\">A PIL Image, numpy array, path or URL for the default value that Image component is going to take. If callable, the function will be called whenever the app loads to set the initial value of the component.</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>position</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nint\n```\n\n</td>\n<td align=\"left\"><code>0.5</code></td>\n<td align=\"left\">The position of the slider, between 0 and 1.</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>upload_count</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nint\n```\n\n</td>\n<td align=\"left\"><code>1</code></td>\n<td align=\"left\">The number of images that can be uploaded to the component. 1 or 2.</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>height</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\">Height of the displayed image in pixels.</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>width</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\">Width of the displayed image in pixels.</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>type</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\n\"numpy\" | \"pil\" | \"filepath\"\n```\n\n</td>\n<td align=\"left\"><code>\"numpy\"</code></td>\n<td align=\"left\">The format the image is converted to before being passed into the prediction function. \"numpy\" converts the image to a numpy array with shape (height, width, 3) and values from 0 to 255, \"pil\" converts the image to a PIL image object, \"filepath\" passes a str path to a temporary file containing the image.</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\">component name in interface.</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, run the function 'every' number of seconds while the client connection is open. Has no effect otherwise. Queue must be enabled. The event can be accessed (e.g. to cancel it) via this component's .load_event attribute.</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\">if True, will display label.</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>show_download_button</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\">If True, will display button to download image.</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\">If True, will place the component in a container - providing some extra padding around the border.</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\">relative width compared to adjacent Components in a Row. For example, if Component A has scale=2, and Component B has scale=1, A will be twice as wide as B. Should be an integer.</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>160</code></td>\n<td align=\"left\">minimum pixel width, will wrap if not sufficient screen space to satisfy this value. If a certain scale value results in this Component being narrower than min_width, the min_width parameter will be respected first.</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\">if True, will allow users to upload and edit an image; if False, can only be used to display images. If not provided, this is inferred based on whether the component is used as an input or output.</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\">If False, component will be hidden.</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>show_share_button</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\">If True, will show a share icon in the corner of the component that allows user to share outputs to Hugging Face Spaces Discussions. If False, icon does not appear. If set to None (default behavior), then the icon appears if this Gradio app is launched on Spaces, but not otherwise.</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>slider_color</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\">The color of the slider separator.</td>\n</tr>\n</tbody></table>\n\n\n### Events\n\n| name | description |\n|:-----|:------------|\n| `change` | Triggered when the value of the ImageSlider 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| `upload` | This listener is triggered when the user uploads a file into the ImageSlider. |\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, tuple of images in the requested format.\n- **As input:** Should return, image as a numpy array, PIL Image, string/Path filepath, or string URL.\n\n ```python\n def predict(\n     value: tuple[str, str]\n    | tuple[PIL.Image.Image, PIL.Image.Image]\n    | tuple[numpy.ndarray, numpy.ndarray]\n    | None\n ) -> tuple[str, str]\n    | tuple[PIL.Image.Image, PIL.Image.Image]\n    | tuple[numpy.ndarray, numpy.ndarray]\n    | None:\n     return value\n ```\n \n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A Gradio component for comparing two images.  This component can be used in several ways:  - as a **unified input / output** where users will upload a single image and an inference function will generate an image it can be compared to (see demo), - as a **manual upload input** allowing users to compare two of their own images (which can then be passed along elsewhere, e.g. to a model),  - as **static output component** allowing users to compare two images generated by an inference function.",
    "version": "0.0.20",
    "project_urls": {
        "repository": "https://github.com/pngwn/gradio-imageslider"
    },
    "split_keywords": [
        "gradio",
        " gradio custom component",
        " machine learning",
        " reproducibility",
        " visualization"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "38e5c33f36a4fd0bd8207bdb0761513387bfbd28b54f51d31265e93fff2d1b1b",
                "md5": "d80282740906fc17629149e40b5fd29c",
                "sha256": "c73d155ce14a63f3fceb7547e8238e93c12c9acaecf7445cf8f281aa880cac79"
            },
            "downloads": -1,
            "filename": "gradio_imageslider-0.0.20-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d80282740906fc17629149e40b5fd29c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 101455,
            "upload_time": "2024-04-19T14:41:09",
            "upload_time_iso_8601": "2024-04-19T14:41:09.863940Z",
            "url": "https://files.pythonhosted.org/packages/38/e5/c33f36a4fd0bd8207bdb0761513387bfbd28b54f51d31265e93fff2d1b1b/gradio_imageslider-0.0.20-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4e20aadd2089f4b45abb8f8a407ad124c6a0bda35298bb44af56cc160ec6d945",
                "md5": "5160bac3512985547abc680685d1ab1c",
                "sha256": "a1421c3239cce2a01160852cdc0962292230418384a0cff3b0307a95a451643f"
            },
            "downloads": -1,
            "filename": "gradio_imageslider-0.0.20.tar.gz",
            "has_sig": false,
            "md5_digest": "5160bac3512985547abc680685d1ab1c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 256548,
            "upload_time": "2024-04-19T14:41:11",
            "upload_time_iso_8601": "2024-04-19T14:41:11.938664Z",
            "url": "https://files.pythonhosted.org/packages/4e/20/aadd2089f4b45abb8f8a407ad124c6a0bda35298bb44af56cc160ec6d945/gradio_imageslider-0.0.20.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-19 14:41:11",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "pngwn",
    "github_project": "gradio-imageslider",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "gradio-imageslider"
}
        
Elapsed time: 0.24023s