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
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 - this custom component is heavily adapted from their work.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gradio_sbmp_promptable_image-0.0.3.tar.gz.
File metadata
- Download URL: gradio_sbmp_promptable_image-0.0.3.tar.gz
- Upload date:
- Size: 1.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
43a29cd083443951ab831e77d0303c089991a9236bda8426eda8ddc47ee8bf35
|
|
| MD5 |
11d7de76b82297b4f8be3e93fb754a2a
|
|
| BLAKE2b-256 |
c110bc63d4ff29437af6e30e8cb06a62f4c7cc11cce2ac0ac3d1997855e9f383
|
File details
Details for the file gradio_sbmp_promptable_image-0.0.3-py3-none-any.whl.
File metadata
- Download URL: gradio_sbmp_promptable_image-0.0.3-py3-none-any.whl
- Upload date:
- Size: 104.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b3ba0b194e87a965d2efab4daeb52543ec9e441934821b7d84fc1c874e0edb3e
|
|
| MD5 |
2ba3f8e8a3de02815605d4c2240417e3
|
|
| BLAKE2b-256 |
2722813291f785e7d9f4181382ba772047c812e1eb742c5fa04959a6bfba4fae
|