Metadata-Version: 2.3
Name: gradio_sbmp_promptable_image
Version: 0.0.2
Summary: A webcam-compatible Gradio input image component enabling prompting with the most recently drawn bounding box and multiple points.
Author: ncstiles
License-Expression: MIT
Keywords: gradio-custom-component,gradio-template-Image
Classifier: Development Status :: 3 - Alpha
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Scientific/Engineering :: Visualization
Requires-Python: >=3.8
Requires-Dist: gradio<5.0,>=4.0
Provides-Extra: dev
Requires-Dist: build; extra == 'dev'
Requires-Dist: twine; extra == 'dev'
Description-Content-Type: text/markdown


# `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

YELLOW = (255, 244, 79)
PURPLE = (177, 157, 217)

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

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

    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 = [(x,y) for x,y,label in 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, PURPLE, thickness=10)

    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), YELLOW, 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.


