Skip to main content

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

Project description

gradio_sbmp_promptable_image

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

Installation

pip install gradio_sbmp_promptable_image

Usage

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 - this custom component is heavily adapted from their work.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gradio_sbmp_promptable_image-0.0.2.tar.gz (1.0 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gradio_sbmp_promptable_image-0.0.2-py3-none-any.whl (104.1 kB view details)

Uploaded Python 3

File details

Details for the file gradio_sbmp_promptable_image-0.0.2.tar.gz.

File metadata

File hashes

Hashes for gradio_sbmp_promptable_image-0.0.2.tar.gz
Algorithm Hash digest
SHA256 0f29ca749f74c0100e9aa9507b3512a4bab37866aa5ac11c36fdbde7c1faed6a
MD5 853a48a8e92a45b2ababcd8d9c2a44b5
BLAKE2b-256 98bcf71b784f06e39160ab0f0005c752c41971e8026bc3c30bad4dde818a7ad0

See more details on using hashes here.

File details

Details for the file gradio_sbmp_promptable_image-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for gradio_sbmp_promptable_image-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 26b4fbec7e6f913f7d5136962d09a0111ba6a6690f6bf0406f33baf4bb689c89
MD5 9e9241cecf894e19681c4f6c7e1fe862
BLAKE2b-256 9cce5c85d44d251d2b50aec6d6d73592f2a06a28c1b38efab7da6fc4e933b5ac

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page