Skip to main content

A webcam-compatible Gradio input image component enabling prompting with bounding boxes.

Project description

gradio_box_promptable_image

A webcam-compatible Gradio input image component enabling prompting with bounding boxes.

Installation

pip install gradio_box_promptable_image

Usage

import gradio as gr
from gradio_box_promptable_image import BoxPromptableImage
import cv2

YELLOW = (255, 244, 79)

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

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']
    box_inputs = get_box_inputs(points)

    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,
    BoxPromptableImage(),
    gr.Image(),
    examples=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_box_promptable_image-0.0.1.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_box_promptable_image-0.0.1-py3-none-any.whl (103.7 kB view details)

Uploaded Python 3

File details

Details for the file gradio_box_promptable_image-0.0.1.tar.gz.

File metadata

File hashes

Hashes for gradio_box_promptable_image-0.0.1.tar.gz
Algorithm Hash digest
SHA256 51f3bfb9877db4485c07aecf0bd93d18c9204854fe652bed06e3305d2abe3932
MD5 f253808c0c69dfec14b8226da083c0ff
BLAKE2b-256 bda1d87d4711e16cde39b03442d037d4d3867061ca1cfeb7be57d6c10129d354

See more details on using hashes here.

File details

Details for the file gradio_box_promptable_image-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for gradio_box_promptable_image-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fb66466dcd04bfb4440806e47014a173de181c4c71f370690fa9d7cdc45e9b3b
MD5 98f0a1b242aadbf2186d05981ff60aca
BLAKE2b-256 2b2b89fd704f4396cceacfad3e6ac75a9589f4e06d484c881c2090274aaca0f6

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