gradio-image-annotation 0.0.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. gradio_image_annotation-0.0.2/.gitignore +9 -0
  2. gradio_image_annotation-0.0.2/PKG-INFO +454 -0
  3. gradio_image_annotation-0.0.2/README.md +428 -0
  4. gradio_image_annotation-0.0.2/README_.md +96 -0
  5. gradio_image_annotation-0.0.2/backend/gradio_image_annotation/__init__.py +4 -0
  6. gradio_image_annotation-0.0.2/backend/gradio_image_annotation/image_annotator.py +293 -0
  7. gradio_image_annotation-0.0.2/backend/gradio_image_annotation/image_annotator.pyi +411 -0
  8. gradio_image_annotation-0.0.2/backend/gradio_image_annotation/templates/component/__vite-browser-external-2447137e.js +4 -0
  9. gradio_image_annotation-0.0.2/backend/gradio_image_annotation/templates/component/index.js +12777 -0
  10. gradio_image_annotation-0.0.2/backend/gradio_image_annotation/templates/component/style.css +1 -0
  11. gradio_image_annotation-0.0.2/backend/gradio_image_annotation/templates/component/wrapper-6f348d45-f837cf34.js +2455 -0
  12. gradio_image_annotation-0.0.2/backend/gradio_image_annotation/templates/example/index.js +6400 -0
  13. gradio_image_annotation-0.0.2/backend/gradio_image_annotation/templates/example/style.css +1 -0
  14. gradio_image_annotation-0.0.2/demo/__init__.py +0 -0
  15. gradio_image_annotation-0.0.2/demo/app.py +56 -0
  16. gradio_image_annotation-0.0.2/demo/css.css +157 -0
  17. gradio_image_annotation-0.0.2/demo/space.py +178 -0
  18. gradio_image_annotation-0.0.2/frontend/Example.svelte +50 -0
  19. gradio_image_annotation-0.0.2/frontend/Index.svelte +117 -0
  20. gradio_image_annotation-0.0.2/frontend/package-lock.json +1124 -0
  21. gradio_image_annotation-0.0.2/frontend/package.json +31 -0
  22. gradio_image_annotation-0.0.2/frontend/shared/AnnotatedImageData.ts +7 -0
  23. gradio_image_annotation-0.0.2/frontend/shared/Box.ts +324 -0
  24. gradio_image_annotation-0.0.2/frontend/shared/Canvas.svelte +417 -0
  25. gradio_image_annotation-0.0.2/frontend/shared/ClearImage.svelte +30 -0
  26. gradio_image_annotation-0.0.2/frontend/shared/Colors.js +15 -0
  27. gradio_image_annotation-0.0.2/frontend/shared/ImageAnnotator.svelte +197 -0
  28. gradio_image_annotation-0.0.2/frontend/shared/ImageCanvas.svelte +58 -0
  29. gradio_image_annotation-0.0.2/frontend/shared/ModalBox.svelte +138 -0
  30. gradio_image_annotation-0.0.2/frontend/shared/icons/Add.svelte +14 -0
  31. gradio_image_annotation-0.0.2/frontend/shared/icons/index.ts +1 -0
  32. gradio_image_annotation-0.0.2/frontend/shared/index.ts +1 -0
  33. gradio_image_annotation-0.0.2/frontend/shared/patched_dropdown/CHANGELOG.md +246 -0
  34. gradio_image_annotation-0.0.2/frontend/shared/patched_dropdown/Dropdown.stories.svelte +60 -0
  35. gradio_image_annotation-0.0.2/frontend/shared/patched_dropdown/Example.svelte +33 -0
  36. gradio_image_annotation-0.0.2/frontend/shared/patched_dropdown/Index.svelte +99 -0
  37. gradio_image_annotation-0.0.2/frontend/shared/patched_dropdown/LICENSE +201 -0
  38. gradio_image_annotation-0.0.2/frontend/shared/patched_dropdown/Multiselect.stories.svelte +48 -0
  39. gradio_image_annotation-0.0.2/frontend/shared/patched_dropdown/README.md +44 -0
  40. gradio_image_annotation-0.0.2/frontend/shared/patched_dropdown/dropdown.test.ts +515 -0
  41. gradio_image_annotation-0.0.2/frontend/shared/patched_dropdown/package.json +21 -0
  42. gradio_image_annotation-0.0.2/frontend/shared/patched_dropdown/shared/Dropdown.svelte +326 -0
  43. gradio_image_annotation-0.0.2/frontend/shared/patched_dropdown/shared/DropdownOptions.svelte +144 -0
  44. gradio_image_annotation-0.0.2/frontend/shared/patched_dropdown/shared/Multiselect.svelte +416 -0
  45. gradio_image_annotation-0.0.2/frontend/shared/patched_dropdown/shared/utils.ts +56 -0
  46. gradio_image_annotation-0.0.2/frontend/shared/utils.ts +29 -0
  47. gradio_image_annotation-0.0.2/images/demo_1.png +0 -0
  48. gradio_image_annotation-0.0.2/images/demo_2.png +0 -0
  49. gradio_image_annotation-0.0.2/package-lock.json +6 -0
  50. gradio_image_annotation-0.0.2/pyproject.toml +42 -0
@@ -0,0 +1,9 @@
1
+ .eggs/
2
+ dist/
3
+ *.pyc
4
+ __pycache__/
5
+ *.py[cod]
6
+ *$py.class
7
+ __tmp/*
8
+ *.pyi
9
+ node_modules
@@ -0,0 +1,454 @@
1
+ Metadata-Version: 2.3
2
+ Name: gradio_image_annotation
3
+ Version: 0.0.2
4
+ Summary: A component that can be used to annotate images with bounding boxes.
5
+ Author-email: YOUR NAME <YOUREMAIL@domain.com>
6
+ License-Expression: MIT
7
+ Keywords: annotate,annotator,bounding box,boxes,gradio-custom-component,gradio-template-Image
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: License :: OSI Approved :: Apache Software License
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3 :: Only
13
+ Classifier: Programming Language :: Python :: 3.8
14
+ Classifier: Programming Language :: Python :: 3.9
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Topic :: Scientific/Engineering
18
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
19
+ Classifier: Topic :: Scientific/Engineering :: Visualization
20
+ Requires-Python: >=3.8
21
+ Requires-Dist: gradio<5.0,>=4.0
22
+ Provides-Extra: dev
23
+ Requires-Dist: build; extra == 'dev'
24
+ Requires-Dist: twine; extra == 'dev'
25
+ Description-Content-Type: text/markdown
26
+
27
+
28
+ # `gradio_image_annotation`
29
+ <a href="https://pypi.org/project/gradio_image_annotation/" target="_blank"><img alt="PyPI - Version" src="https://img.shields.io/pypi/v/gradio_image_annotation"></a>
30
+
31
+ A component that can be used to annotate images with bounding boxes.
32
+
33
+ ## Installation
34
+
35
+ ```bash
36
+ pip install gradio_image_annotation
37
+ ```
38
+
39
+ ## Usage
40
+
41
+ ```python
42
+ import gradio as gr
43
+ from gradio_image_annotation import image_annotator
44
+
45
+ example = {
46
+ "image": "https://raw.githubusercontent.com/gradio-app/gradio/main/guides/assets/logo.png",
47
+ "boxes": [
48
+ {
49
+ "xmin": 30,
50
+ "ymin": 70,
51
+ "xmax": 530,
52
+ "ymax": 500,
53
+ "label": "Gradio",
54
+ "color": (250, 185, 0),
55
+ }
56
+ ]
57
+ }
58
+
59
+
60
+ def crop(annotations):
61
+ if annotations["boxes"]:
62
+ box = annotations["boxes"][0]
63
+ return annotations["image"][
64
+ box["ymin"]:box["ymax"],
65
+ box["xmin"]:box["xmax"]
66
+ ]
67
+ return None
68
+
69
+
70
+ def get_boxes_json(annotations):
71
+ return [
72
+ {k: box[k]
73
+ for k in box if k in ("xmin", "ymin", "xmax", "ymax", "label")}
74
+ for box in annotations["boxes"]
75
+ ]
76
+
77
+
78
+ with gr.Blocks() as demo:
79
+ with gr.Tab("Crop"):
80
+ with gr.Row():
81
+ annotator_crop = image_annotator(example, image_type="numpy")
82
+ image_crop = gr.Image()
83
+ button_crop = gr.Button("Crop")
84
+ button_crop.click(crop, annotator_crop, image_crop)
85
+ with gr.Tab("Object annotation"):
86
+ annotator = image_annotator(
87
+ {"image": "https://gradio-builds.s3.amazonaws.com/demo-files/base.png"},
88
+ label_list=["Person", "Vehicle"],
89
+ label_colors=[(0, 255, 0), (255, 0, 0)],
90
+ )
91
+ button_get = gr.Button("Get bounding boxes")
92
+ json_boxes = gr.JSON()
93
+ button_get.click(get_boxes_json, annotator, json_boxes)
94
+
95
+
96
+ if __name__ == "__main__":
97
+ demo.launch()
98
+
99
+ ```
100
+
101
+ ## `image_annotator`
102
+
103
+ ### Initialization
104
+
105
+ <table>
106
+ <thead>
107
+ <tr>
108
+ <th align="left">name</th>
109
+ <th align="left" style="width: 25%;">type</th>
110
+ <th align="left">default</th>
111
+ <th align="left">description</th>
112
+ </tr>
113
+ </thead>
114
+ <tbody>
115
+ <tr>
116
+ <td align="left"><code>value</code></td>
117
+ <td align="left" style="width: 25%;">
118
+
119
+ ```python
120
+ dict | None
121
+ ```
122
+
123
+ </td>
124
+ <td align="left"><code>None</code></td>
125
+ <td align="left">A dict or None. The dictionary must contain a key 'image' with either an URL to an image, a numpy image or a PIL image. Optionally it may contain a key 'boxes' with a list of boxes. Each box must be a dict wit the keys: 'xmin', 'ymin', 'xmax' and 'ymax' with the absolute image coordinates of the box. Optionally can also include the keys 'label' and 'color' describing the label and color of the box. Color must be a tuple of RGB values (e.g. `(255,255,255)`).</td>
126
+ </tr>
127
+
128
+ <tr>
129
+ <td align="left"><code>boxes_alpha</code></td>
130
+ <td align="left" style="width: 25%;">
131
+
132
+ ```python
133
+ float | None
134
+ ```
135
+
136
+ </td>
137
+ <td align="left"><code>None</code></td>
138
+ <td align="left">Opacity of the bounding boxes 0 and 1.</td>
139
+ </tr>
140
+
141
+ <tr>
142
+ <td align="left"><code>label_list</code></td>
143
+ <td align="left" style="width: 25%;">
144
+
145
+ ```python
146
+ list[str] | None
147
+ ```
148
+
149
+ </td>
150
+ <td align="left"><code>None</code></td>
151
+ <td align="left">List of valid labels.</td>
152
+ </tr>
153
+
154
+ <tr>
155
+ <td align="left"><code>label_colors</code></td>
156
+ <td align="left" style="width: 25%;">
157
+
158
+ ```python
159
+ list[str] | None
160
+ ```
161
+
162
+ </td>
163
+ <td align="left"><code>None</code></td>
164
+ <td align="left">Optional list of colors for each label when `label_list` is used. Colors must be a tuple of RGB values (e.g. `(255,255,255)`).</td>
165
+ </tr>
166
+
167
+ <tr>
168
+ <td align="left"><code>box_min_size</code></td>
169
+ <td align="left" style="width: 25%;">
170
+
171
+ ```python
172
+ int | None
173
+ ```
174
+
175
+ </td>
176
+ <td align="left"><code>None</code></td>
177
+ <td align="left">Minimum valid bounding box size.</td>
178
+ </tr>
179
+
180
+ <tr>
181
+ <td align="left"><code>height</code></td>
182
+ <td align="left" style="width: 25%;">
183
+
184
+ ```python
185
+ int | str | None
186
+ ```
187
+
188
+ </td>
189
+ <td align="left"><code>None</code></td>
190
+ <td align="left">The height of the displayed image, specified in pixels if a number is passed, or in CSS units if a string is passed.</td>
191
+ </tr>
192
+
193
+ <tr>
194
+ <td align="left"><code>width</code></td>
195
+ <td align="left" style="width: 25%;">
196
+
197
+ ```python
198
+ int | str | None
199
+ ```
200
+
201
+ </td>
202
+ <td align="left"><code>None</code></td>
203
+ <td align="left">The width of the displayed image, specified in pixels if a number is passed, or in CSS units if a string is passed.</td>
204
+ </tr>
205
+
206
+ <tr>
207
+ <td align="left"><code>image_mode</code></td>
208
+ <td align="left" style="width: 25%;">
209
+
210
+ ```python
211
+ "1"
212
+ | "L"
213
+ | "P"
214
+ | "RGB"
215
+ | "RGBA"
216
+ | "CMYK"
217
+ | "YCbCr"
218
+ | "LAB"
219
+ | "HSV"
220
+ | "I"
221
+ | "F"
222
+ ```
223
+
224
+ </td>
225
+ <td align="left"><code>"RGB"</code></td>
226
+ <td align="left">"RGB" if color, or "L" if black and white. See https://pillow.readthedocs.io/en/stable/handbook/concepts.html for other supported image modes and their meaning.</td>
227
+ </tr>
228
+
229
+ <tr>
230
+ <td align="left"><code>sources</code></td>
231
+ <td align="left" style="width: 25%;">
232
+
233
+ ```python
234
+ list["upload" | "clipboard"] | None
235
+ ```
236
+
237
+ </td>
238
+ <td align="left"><code>["upload", "clipboard"]</code></td>
239
+ <td align="left">List of sources for the image. "upload" creates a box where user can drop an image file, "clipboard" allows users to paste an image from the clipboard. If None, defaults to ["upload", "clipboard"].</td>
240
+ </tr>
241
+
242
+ <tr>
243
+ <td align="left"><code>image_type</code></td>
244
+ <td align="left" style="width: 25%;">
245
+
246
+ ```python
247
+ "numpy" | "pil" | "filepath"
248
+ ```
249
+
250
+ </td>
251
+ <td align="left"><code>"numpy"</code></td>
252
+ <td align="left">The format the image is converted before being passed into the prediction function. "numpy" converts the image to a numpy array with shape (height, width, 3) and values from 0 to 255, "pil" converts the image to a PIL image object, "filepath" passes a str path to a temporary file containing the image. If the image is SVG, the `type` is ignored and the filepath of the SVG is returned.</td>
253
+ </tr>
254
+
255
+ <tr>
256
+ <td align="left"><code>label</code></td>
257
+ <td align="left" style="width: 25%;">
258
+
259
+ ```python
260
+ str | None
261
+ ```
262
+
263
+ </td>
264
+ <td align="left"><code>None</code></td>
265
+ <td align="left">The label for this component. Appears above the component and is also used as the header if there are a table of examples for this component. If None and used in a `gr.Interface`, the label will be the name of the parameter this component is assigned to.</td>
266
+ </tr>
267
+
268
+ <tr>
269
+ <td align="left"><code>container</code></td>
270
+ <td align="left" style="width: 25%;">
271
+
272
+ ```python
273
+ bool
274
+ ```
275
+
276
+ </td>
277
+ <td align="left"><code>True</code></td>
278
+ <td align="left">If True, will place the component in a container - providing some extra padding around the border.</td>
279
+ </tr>
280
+
281
+ <tr>
282
+ <td align="left"><code>scale</code></td>
283
+ <td align="left" style="width: 25%;">
284
+
285
+ ```python
286
+ int | None
287
+ ```
288
+
289
+ </td>
290
+ <td align="left"><code>None</code></td>
291
+ <td align="left">relative size compared to adjacent Components. For example if Components A and B are in a Row, and A has scale=2, and B has scale=1, A will be twice as wide as B. Should be an integer. scale applies in Rows, and to top-level Components in Blocks where fill_height=True.</td>
292
+ </tr>
293
+
294
+ <tr>
295
+ <td align="left"><code>min_width</code></td>
296
+ <td align="left" style="width: 25%;">
297
+
298
+ ```python
299
+ int
300
+ ```
301
+
302
+ </td>
303
+ <td align="left"><code>160</code></td>
304
+ <td align="left">minimum pixel width, will wrap if not sufficient screen space to satisfy this value. If a certain scale value results in this Component being narrower than min_width, the min_width parameter will be respected first.</td>
305
+ </tr>
306
+
307
+ <tr>
308
+ <td align="left"><code>interactive</code></td>
309
+ <td align="left" style="width: 25%;">
310
+
311
+ ```python
312
+ bool | None
313
+ ```
314
+
315
+ </td>
316
+ <td align="left"><code>True</code></td>
317
+ <td align="left">if True, will allow users to upload and annotate an image; if False, can only be used to display annotated images.</td>
318
+ </tr>
319
+
320
+ <tr>
321
+ <td align="left"><code>visible</code></td>
322
+ <td align="left" style="width: 25%;">
323
+
324
+ ```python
325
+ bool
326
+ ```
327
+
328
+ </td>
329
+ <td align="left"><code>True</code></td>
330
+ <td align="left">If False, component will be hidden.</td>
331
+ </tr>
332
+
333
+ <tr>
334
+ <td align="left"><code>elem_id</code></td>
335
+ <td align="left" style="width: 25%;">
336
+
337
+ ```python
338
+ str | None
339
+ ```
340
+
341
+ </td>
342
+ <td align="left"><code>None</code></td>
343
+ <td align="left">An optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles.</td>
344
+ </tr>
345
+
346
+ <tr>
347
+ <td align="left"><code>elem_classes</code></td>
348
+ <td align="left" style="width: 25%;">
349
+
350
+ ```python
351
+ list[str] | str | None
352
+ ```
353
+
354
+ </td>
355
+ <td align="left"><code>None</code></td>
356
+ <td align="left">An optional list of strings that are assigned as the classes of this component in the HTML DOM. Can be used for targeting CSS styles.</td>
357
+ </tr>
358
+
359
+ <tr>
360
+ <td align="left"><code>render</code></td>
361
+ <td align="left" style="width: 25%;">
362
+
363
+ ```python
364
+ bool
365
+ ```
366
+
367
+ </td>
368
+ <td align="left"><code>True</code></td>
369
+ <td align="left">If False, component will not render be rendered in the Blocks context. Should be used if the intention is to assign event listeners now but render the component later.</td>
370
+ </tr>
371
+
372
+ <tr>
373
+ <td align="left"><code>show_label</code></td>
374
+ <td align="left" style="width: 25%;">
375
+
376
+ ```python
377
+ bool | None
378
+ ```
379
+
380
+ </td>
381
+ <td align="left"><code>None</code></td>
382
+ <td align="left">if True, will display label.</td>
383
+ </tr>
384
+
385
+ <tr>
386
+ <td align="left"><code>show_download_button</code></td>
387
+ <td align="left" style="width: 25%;">
388
+
389
+ ```python
390
+ bool
391
+ ```
392
+
393
+ </td>
394
+ <td align="left"><code>True</code></td>
395
+ <td align="left">If True, will show a button to download the image.</td>
396
+ </tr>
397
+
398
+ <tr>
399
+ <td align="left"><code>show_share_button</code></td>
400
+ <td align="left" style="width: 25%;">
401
+
402
+ ```python
403
+ bool | None
404
+ ```
405
+
406
+ </td>
407
+ <td align="left"><code>None</code></td>
408
+ <td align="left">If True, will show a share icon in the corner of the component that allows user to share outputs to Hugging Face Spaces Discussions. If False, icon does not appear. If set to None (default behavior), then the icon appears if this Gradio app is launched on Spaces, but not otherwise.</td>
409
+ </tr>
410
+
411
+ <tr>
412
+ <td align="left"><code>show_clear_button</code></td>
413
+ <td align="left" style="width: 25%;">
414
+
415
+ ```python
416
+ bool | None
417
+ ```
418
+
419
+ </td>
420
+ <td align="left"><code>True</code></td>
421
+ <td align="left">If True, will show a clear button.</td>
422
+ </tr>
423
+ </tbody></table>
424
+
425
+
426
+ ### Events
427
+
428
+ | name | description |
429
+ |:-----|:------------|
430
+ | `clear` | This listener is triggered when the user clears the image_annotator using the X button for the component. |
431
+ | `change` | Triggered when the value of the image_annotator changes either because of user input (e.g. a user types in a textbox) OR because of a function update (e.g. an image receives a value from the output of an event trigger). See `.input()` for a listener that is only triggered by user input. |
432
+ | `upload` | This listener is triggered when the user uploads a file into the image_annotator. |
433
+
434
+
435
+
436
+ ### User function
437
+
438
+ The impact on the users predict function varies depending on whether the component is used as an input or output for an event (or both).
439
+
440
+ - When used as an Input, the component only impacts the input signature of the user function.
441
+ - When used as an output, the component only impacts the return signature of the user function.
442
+
443
+ The code snippet below is accurate in cases where the component is used as both an input and an output.
444
+
445
+ - **As output:** Is passed, a dict with the image and boxes or None.
446
+ - **As input:** Should return, a dict with an image and an optional list of boxes or None.
447
+
448
+ ```python
449
+ def predict(
450
+ value: dict | None
451
+ ) -> dict | None:
452
+ return value
453
+ ```
454
+