Skip to content

ncstiles/gradio-box-promptable-image

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published