gradio-sbmp-promptable-image


Namegradio-sbmp-promptable-image JSON
Version 0.0.3 PyPI version JSON
download
home_pageNone
SummaryA webcam-compatible Gradio input image component enabling prompting with the most recently drawn bounding box and multiple points.
upload_time2024-03-20 21:49:31
maintainerNone
docs_urlNone
authorncstiles
requires_python>=3.8
licenseNone
keywords gradio-custom-component gradio-template-image
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# `gradio_sbmp_promptable_image`

A webcam-compatible Gradio input image component enabling prompting with the most recently drawn bounding box and multiple points.

## Installation

```bash
pip install gradio_sbmp_promptable_image
```

## Usage

```python

import gradio as gr
from gradio_sbmp_promptable_image import SBMPPromptableImage
import cv2

BLUE = (135, 206, 235)
PINK = (239, 149, 186)

image_examples = [{"image": "images/cat.png", "points": []}]

def get_point_inputs(prompts):
    point_inputs = []
    for prompt in prompts:
        if prompt[5] == 4.0:
            point_inputs.append((prompt[0], prompt[1], prompt[2]))

    return point_inputs

def get_box_inputs(prompts):
    box_inputs = []
    for prompt in prompts:
        if prompt[2] == 2.0 and prompt[5] == 3.0:
            box_inputs.append((prompt[0], prompt[1], prompt[3], prompt[4]))

    return box_inputs

def process_input(input_dict):
    img, points = input_dict['image'], input_dict['points']

    point_inputs = get_point_inputs(points)
    box_inputs = get_box_inputs(points)

    for point in point_inputs:
        x, y = int(point[0]), int(point[1])
        cv2.circle(img, (x, y), 2, (0, 0, 0), thickness=10)
        if point[2] == 1:
            cv2.circle(img, (x, y), 2, BLUE, thickness=8)
        else:
            cv2.circle(img, (x, y), 2, PINK, thickness=8)

    for box in box_inputs:
        x1, y1, x2, y2 = int(box[0]), int(box[1]), int(box[2]), int(box[3])
        cv2.rectangle(img, (x1, y1), (x2, y2), (255, 0, 0), 2)

    return img

demo = gr.Interface(
    process_input,
    SBMPPromptableImage(),
    gr.Image(),
    examples=image_examples,
)

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

```

## Acknowledgements

Special thanks to the creators of [gradio-image-prompter](https://github.com/PhyscalX/gradio-image-prompter/tree/main?tab=readme-ov-file) - this custom component is heavily adapted from their work.



            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "gradio-sbmp-promptable-image",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "gradio-custom-component, gradio-template-Image",
    "author": "ncstiles",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/c1/10/bc63d4ff29437af6e30e8cb06a62f4c7cc11cce2ac0ac3d1997855e9f383/gradio_sbmp_promptable_image-0.0.3.tar.gz",
    "platform": null,
    "description": "\n# `gradio_sbmp_promptable_image`\n\nA webcam-compatible Gradio input image component enabling prompting with the most recently drawn bounding box and multiple points.\n\n## Installation\n\n```bash\npip install gradio_sbmp_promptable_image\n```\n\n## Usage\n\n```python\n\nimport gradio as gr\nfrom gradio_sbmp_promptable_image import SBMPPromptableImage\nimport cv2\n\nBLUE = (135, 206, 235)\nPINK = (239, 149, 186)\n\nimage_examples = [{\"image\": \"images/cat.png\", \"points\": []}]\n\ndef get_point_inputs(prompts):\n    point_inputs = []\n    for prompt in prompts:\n        if prompt[5] == 4.0:\n            point_inputs.append((prompt[0], prompt[1], prompt[2]))\n\n    return point_inputs\n\ndef get_box_inputs(prompts):\n    box_inputs = []\n    for prompt in prompts:\n        if prompt[2] == 2.0 and prompt[5] == 3.0:\n            box_inputs.append((prompt[0], prompt[1], prompt[3], prompt[4]))\n\n    return box_inputs\n\ndef process_input(input_dict):\n    img, points = input_dict['image'], input_dict['points']\n\n    point_inputs = get_point_inputs(points)\n    box_inputs = get_box_inputs(points)\n\n    for point in point_inputs:\n        x, y = int(point[0]), int(point[1])\n        cv2.circle(img, (x, y), 2, (0, 0, 0), thickness=10)\n        if point[2] == 1:\n            cv2.circle(img, (x, y), 2, BLUE, thickness=8)\n        else:\n            cv2.circle(img, (x, y), 2, PINK, thickness=8)\n\n    for box in box_inputs:\n        x1, y1, x2, y2 = int(box[0]), int(box[1]), int(box[2]), int(box[3])\n        cv2.rectangle(img, (x1, y1), (x2, y2), (255, 0, 0), 2)\n\n    return img\n\ndemo = gr.Interface(\n    process_input,\n    SBMPPromptableImage(),\n    gr.Image(),\n    examples=image_examples,\n)\n\nif __name__ == \"__main__\":\n    demo.launch()\n\n```\n\n## Acknowledgements\n\nSpecial thanks to the creators of [gradio-image-prompter](https://github.com/PhyscalX/gradio-image-prompter/tree/main?tab=readme-ov-file) - this custom component is heavily adapted from their work.\n\n\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A webcam-compatible Gradio input image component enabling prompting with the most recently drawn bounding box and multiple points.",
    "version": "0.0.3",
    "project_urls": null,
    "split_keywords": [
        "gradio-custom-component",
        " gradio-template-image"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2722813291f785e7d9f4181382ba772047c812e1eb742c5fa04959a6bfba4fae",
                "md5": "2ba3f8e8a3de02815605d4c2240417e3",
                "sha256": "b3ba0b194e87a965d2efab4daeb52543ec9e441934821b7d84fc1c874e0edb3e"
            },
            "downloads": -1,
            "filename": "gradio_sbmp_promptable_image-0.0.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2ba3f8e8a3de02815605d4c2240417e3",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 104135,
            "upload_time": "2024-03-20T21:49:29",
            "upload_time_iso_8601": "2024-03-20T21:49:29.106386Z",
            "url": "https://files.pythonhosted.org/packages/27/22/813291f785e7d9f4181382ba772047c812e1eb742c5fa04959a6bfba4fae/gradio_sbmp_promptable_image-0.0.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c110bc63d4ff29437af6e30e8cb06a62f4c7cc11cce2ac0ac3d1997855e9f383",
                "md5": "11d7de76b82297b4f8be3e93fb754a2a",
                "sha256": "43a29cd083443951ab831e77d0303c089991a9236bda8426eda8ddc47ee8bf35"
            },
            "downloads": -1,
            "filename": "gradio_sbmp_promptable_image-0.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "11d7de76b82297b4f8be3e93fb754a2a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 1010788,
            "upload_time": "2024-03-20T21:49:31",
            "upload_time_iso_8601": "2024-03-20T21:49:31.081877Z",
            "url": "https://files.pythonhosted.org/packages/c1/10/bc63d4ff29437af6e30e8cb06a62f4c7cc11cce2ac0ac3d1997855e9f383/gradio_sbmp_promptable_image-0.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-20 21:49:31",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "gradio-sbmp-promptable-image"
}
        
Elapsed time: 0.20826s