# `gradio_box_promptable_image`
A webcam-compatible Gradio input image component enabling prompting with bounding boxes.
## Installation
```bash
pip install gradio_box_promptable_image
```
## Usage
```python
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](https://github.com/PhyscalX/gradio-image-prompter/tree/main?tab=readme-ov-file) - this custom component is heavily adapted from their work.
Raw data
{
"_id": null,
"home_page": "",
"name": "gradio-box-promptable-image",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "",
"keywords": "gradio-custom-component,gradio-template-Image",
"author": "ncstiles",
"author_email": "",
"download_url": "https://files.pythonhosted.org/packages/bd/a1/d87d4711e16cde39b03442d037d4d3867061ca1cfeb7be57d6c10129d354/gradio_box_promptable_image-0.0.1.tar.gz",
"platform": null,
"description": "\n# `gradio_box_promptable_image`\n\nA webcam-compatible Gradio input image component enabling prompting with bounding boxes.\n\n## Installation\n\n```bash\npip install gradio_box_promptable_image\n```\n\n## Usage\n\n```python\n\nimport gradio as gr\nfrom gradio_box_promptable_image import BoxPromptableImage\nimport cv2\n\nYELLOW = (255, 244, 79)\n\nexamples = [{\"image\": \"images/cat.png\", \"points\": []}]\n\ndef get_box_inputs(prompts):\n box_inputs = []\n for prompt in prompts:\n if prompt[2] == 2.0 and prompt[5] == 3.0:\n box_inputs.append((prompt[0], prompt[1], prompt[3], prompt[4]))\n\n return box_inputs\n\ndef process_input(input_dict):\n img, points = input_dict['image'], input_dict['points']\n box_inputs = get_box_inputs(points)\n\n for box in box_inputs:\n x1, y1, x2, y2 = int(box[0]), int(box[1]), int(box[2]), int(box[3])\n cv2.rectangle(img, (x1, y1), (x2, y2), YELLOW, 2)\n\n return img\n\ndemo = gr.Interface(\n process_input,\n BoxPromptableImage(),\n gr.Image(),\n examples=examples,\n)\n\nif __name__ == \"__main__\":\n demo.launch()\n\n```\n\n## Acknowledgements\n\nSpecial 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.\n\n\n\n",
"bugtrack_url": null,
"license": "",
"summary": "A webcam-compatible Gradio input image component enabling prompting with bounding boxes.",
"version": "0.0.1",
"project_urls": null,
"split_keywords": [
"gradio-custom-component",
"gradio-template-image"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "2b2b89fd704f4396cceacfad3e6ac75a9589f4e06d484c881c2090274aaca0f6",
"md5": "98f0a1b242aadbf2186d05981ff60aca",
"sha256": "fb66466dcd04bfb4440806e47014a173de181c4c71f370690fa9d7cdc45e9b3b"
},
"downloads": -1,
"filename": "gradio_box_promptable_image-0.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "98f0a1b242aadbf2186d05981ff60aca",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 103689,
"upload_time": "2024-03-18T01:55:14",
"upload_time_iso_8601": "2024-03-18T01:55:14.255468Z",
"url": "https://files.pythonhosted.org/packages/2b/2b/89fd704f4396cceacfad3e6ac75a9589f4e06d484c881c2090274aaca0f6/gradio_box_promptable_image-0.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "bda1d87d4711e16cde39b03442d037d4d3867061ca1cfeb7be57d6c10129d354",
"md5": "f253808c0c69dfec14b8226da083c0ff",
"sha256": "51f3bfb9877db4485c07aecf0bd93d18c9204854fe652bed06e3305d2abe3932"
},
"downloads": -1,
"filename": "gradio_box_promptable_image-0.0.1.tar.gz",
"has_sig": false,
"md5_digest": "f253808c0c69dfec14b8226da083c0ff",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 1013102,
"upload_time": "2024-03-18T01:55:16",
"upload_time_iso_8601": "2024-03-18T01:55:16.733908Z",
"url": "https://files.pythonhosted.org/packages/bd/a1/d87d4711e16cde39b03442d037d4d3867061ca1cfeb7be57d6c10129d354/gradio_box_promptable_image-0.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-03-18 01:55:16",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "gradio-box-promptable-image"
}