edgargg commited on
Commit
0ee0fac
·
verified ·
1 Parent(s): 11227b8

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. README.md +12 -464
  2. requirements.txt +1 -1
README.md CHANGED
@@ -1,469 +1,17 @@
1
 
2
- # `gradio_image_annotation`
3
- <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>
 
 
 
 
 
 
 
4
 
5
- A Gradio component that can be used to annotate images with bounding boxes.
6
 
7
- ## Installation
8
 
9
- ```bash
10
- pip install gradio_image_annotation
11
- ```
12
 
13
- ## Usage
14
-
15
- ```python
16
- import gradio as gr
17
- from gradio_image_annotation import image_annotator
18
-
19
- example = {
20
- "image": "https://raw.githubusercontent.com/gradio-app/gradio/main/guides/assets/logo.png",
21
- "boxes": [
22
- {
23
- "xmin": 30,
24
- "ymin": 70,
25
- "xmax": 530,
26
- "ymax": 500,
27
- "label": "Gradio",
28
- "color": (250, 185, 0),
29
- }
30
- ]
31
- }
32
-
33
-
34
- def crop(annotations):
35
- if annotations["boxes"]:
36
- box = annotations["boxes"][0]
37
- return annotations["image"][
38
- box["ymin"]:box["ymax"],
39
- box["xmin"]:box["xmax"]
40
- ]
41
- return None
42
-
43
-
44
- def get_boxes_json(annotations):
45
- return annotations["boxes"]
46
-
47
- with gr.Blocks() as demo:
48
- with gr.Tab("Object annotation"):
49
- annotator = image_annotator(
50
- {"image": "https://gradio-builds.s3.amazonaws.com/demo-files/base.png"},
51
- label_list=["Person", "Vehicle"],
52
- label_colors=[(0, 255, 0), (255, 0, 0)],
53
-
54
- handle_size=6,
55
- box_thickness=0,
56
- box_selected_thickness=1,
57
- )
58
- button_get = gr.Button("Get bounding boxes")
59
- json_boxes = gr.JSON()
60
- button_get.click(get_boxes_json, annotator, json_boxes)
61
- with gr.Tab("Crop"):
62
- with gr.Row():
63
- annotator_crop = image_annotator(example, image_type="numpy",
64
- handle_size=6,
65
- box_thickness=1,
66
- box_selected_thickness=1,)
67
- image_crop = gr.Image()
68
- button_crop = gr.Button("Crop")
69
- button_crop.click(crop, annotator_crop, image_crop)
70
-
71
-
72
- if __name__ == "__main__":
73
- demo.launch()
74
-
75
- ```
76
-
77
- ## `image_annotator`
78
-
79
- ### Initialization
80
-
81
- <table>
82
- <thead>
83
- <tr>
84
- <th align="left">name</th>
85
- <th align="left" style="width: 25%;">type</th>
86
- <th align="left">default</th>
87
- <th align="left">description</th>
88
- </tr>
89
- </thead>
90
- <tbody>
91
- <tr>
92
- <td align="left"><code>value</code></td>
93
- <td align="left" style="width: 25%;">
94
-
95
- ```python
96
- dict | None
97
- ```
98
-
99
- </td>
100
- <td align="left"><code>None</code></td>
101
- <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>
102
- </tr>
103
-
104
- <tr>
105
- <td align="left"><code>boxes_alpha</code></td>
106
- <td align="left" style="width: 25%;">
107
-
108
- ```python
109
- float | None
110
- ```
111
-
112
- </td>
113
- <td align="left"><code>None</code></td>
114
- <td align="left">Opacity of the bounding boxes 0 and 1.</td>
115
- </tr>
116
-
117
- <tr>
118
- <td align="left"><code>label_list</code></td>
119
- <td align="left" style="width: 25%;">
120
-
121
- ```python
122
- list[str] | None
123
- ```
124
-
125
- </td>
126
- <td align="left"><code>None</code></td>
127
- <td align="left">List of valid labels.</td>
128
- </tr>
129
-
130
- <tr>
131
- <td align="left"><code>label_colors</code></td>
132
- <td align="left" style="width: 25%;">
133
-
134
- ```python
135
- list[str] | None
136
- ```
137
-
138
- </td>
139
- <td align="left"><code>None</code></td>
140
- <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>
141
- </tr>
142
-
143
- <tr>
144
- <td align="left"><code>box_min_size</code></td>
145
- <td align="left" style="width: 25%;">
146
-
147
- ```python
148
- int | None
149
- ```
150
-
151
- </td>
152
- <td align="left"><code>None</code></td>
153
- <td align="left">Minimum valid bounding box size.</td>
154
- </tr>
155
-
156
- <tr>
157
- <td align="left"><code>handle_size</code></td>
158
- <td align="left" style="width: 25%;">
159
-
160
- ```python
161
- int | None
162
- ```
163
-
164
- </td>
165
- <td align="left"><code>None</code></td>
166
- <td align="left">Size of the bounding box resize handles.</td>
167
- </tr>
168
-
169
- <tr>
170
- <td align="left"><code>box_thickness</code></td>
171
- <td align="left" style="width: 25%;">
172
-
173
- ```python
174
- int | None
175
- ```
176
-
177
- </td>
178
- <td align="left"><code>None</code></td>
179
- <td align="left">Thickness of the bounding box outline.</td>
180
- </tr>
181
-
182
- <tr>
183
- <td align="left"><code>box_selected_thickness</code></td>
184
- <td align="left" style="width: 25%;">
185
-
186
- ```python
187
- int | None
188
- ```
189
-
190
- </td>
191
- <td align="left"><code>None</code></td>
192
- <td align="left">Thickness of the bounding box outline when it is selected.</td>
193
- </tr>
194
-
195
- <tr>
196
- <td align="left"><code>height</code></td>
197
- <td align="left" style="width: 25%;">
198
-
199
- ```python
200
- int | str | None
201
- ```
202
-
203
- </td>
204
- <td align="left"><code>None</code></td>
205
- <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>
206
- </tr>
207
-
208
- <tr>
209
- <td align="left"><code>width</code></td>
210
- <td align="left" style="width: 25%;">
211
-
212
- ```python
213
- int | str | None
214
- ```
215
-
216
- </td>
217
- <td align="left"><code>None</code></td>
218
- <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>
219
- </tr>
220
-
221
- <tr>
222
- <td align="left"><code>image_mode</code></td>
223
- <td align="left" style="width: 25%;">
224
-
225
- ```python
226
- "1"
227
- | "L"
228
- | "P"
229
- | "RGB"
230
- | "RGBA"
231
- | "CMYK"
232
- | "YCbCr"
233
- | "LAB"
234
- | "HSV"
235
- | "I"
236
- | "F"
237
- ```
238
-
239
- </td>
240
- <td align="left"><code>"RGB"</code></td>
241
- <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>
242
- </tr>
243
-
244
- <tr>
245
- <td align="left"><code>sources</code></td>
246
- <td align="left" style="width: 25%;">
247
-
248
- ```python
249
- list["upload" | "clipboard"] | None
250
- ```
251
-
252
- </td>
253
- <td align="left"><code>["upload", "clipboard"]</code></td>
254
- <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>
255
- </tr>
256
-
257
- <tr>
258
- <td align="left"><code>image_type</code></td>
259
- <td align="left" style="width: 25%;">
260
-
261
- ```python
262
- "numpy" | "pil" | "filepath"
263
- ```
264
-
265
- </td>
266
- <td align="left"><code>"numpy"</code></td>
267
- <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>
268
- </tr>
269
-
270
- <tr>
271
- <td align="left"><code>label</code></td>
272
- <td align="left" style="width: 25%;">
273
-
274
- ```python
275
- str | None
276
- ```
277
-
278
- </td>
279
- <td align="left"><code>None</code></td>
280
- <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>
281
- </tr>
282
-
283
- <tr>
284
- <td align="left"><code>container</code></td>
285
- <td align="left" style="width: 25%;">
286
-
287
- ```python
288
- bool
289
- ```
290
-
291
- </td>
292
- <td align="left"><code>True</code></td>
293
- <td align="left">If True, will place the component in a container - providing some extra padding around the border.</td>
294
- </tr>
295
-
296
- <tr>
297
- <td align="left"><code>scale</code></td>
298
- <td align="left" style="width: 25%;">
299
-
300
- ```python
301
- int | None
302
- ```
303
-
304
- </td>
305
- <td align="left"><code>None</code></td>
306
- <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>
307
- </tr>
308
-
309
- <tr>
310
- <td align="left"><code>min_width</code></td>
311
- <td align="left" style="width: 25%;">
312
-
313
- ```python
314
- int
315
- ```
316
-
317
- </td>
318
- <td align="left"><code>160</code></td>
319
- <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>
320
- </tr>
321
-
322
- <tr>
323
- <td align="left"><code>interactive</code></td>
324
- <td align="left" style="width: 25%;">
325
-
326
- ```python
327
- bool | None
328
- ```
329
-
330
- </td>
331
- <td align="left"><code>True</code></td>
332
- <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>
333
- </tr>
334
-
335
- <tr>
336
- <td align="left"><code>visible</code></td>
337
- <td align="left" style="width: 25%;">
338
-
339
- ```python
340
- bool
341
- ```
342
-
343
- </td>
344
- <td align="left"><code>True</code></td>
345
- <td align="left">If False, component will be hidden.</td>
346
- </tr>
347
-
348
- <tr>
349
- <td align="left"><code>elem_id</code></td>
350
- <td align="left" style="width: 25%;">
351
-
352
- ```python
353
- str | None
354
- ```
355
-
356
- </td>
357
- <td align="left"><code>None</code></td>
358
- <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>
359
- </tr>
360
-
361
- <tr>
362
- <td align="left"><code>elem_classes</code></td>
363
- <td align="left" style="width: 25%;">
364
-
365
- ```python
366
- list[str] | str | None
367
- ```
368
-
369
- </td>
370
- <td align="left"><code>None</code></td>
371
- <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>
372
- </tr>
373
-
374
- <tr>
375
- <td align="left"><code>render</code></td>
376
- <td align="left" style="width: 25%;">
377
-
378
- ```python
379
- bool
380
- ```
381
-
382
- </td>
383
- <td align="left"><code>True</code></td>
384
- <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>
385
- </tr>
386
-
387
- <tr>
388
- <td align="left"><code>show_label</code></td>
389
- <td align="left" style="width: 25%;">
390
-
391
- ```python
392
- bool | None
393
- ```
394
-
395
- </td>
396
- <td align="left"><code>None</code></td>
397
- <td align="left">if True, will display label.</td>
398
- </tr>
399
-
400
- <tr>
401
- <td align="left"><code>show_download_button</code></td>
402
- <td align="left" style="width: 25%;">
403
-
404
- ```python
405
- bool
406
- ```
407
-
408
- </td>
409
- <td align="left"><code>True</code></td>
410
- <td align="left">If True, will show a button to download the image.</td>
411
- </tr>
412
-
413
- <tr>
414
- <td align="left"><code>show_share_button</code></td>
415
- <td align="left" style="width: 25%;">
416
-
417
- ```python
418
- bool | None
419
- ```
420
-
421
- </td>
422
- <td align="left"><code>None</code></td>
423
- <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>
424
- </tr>
425
-
426
- <tr>
427
- <td align="left"><code>show_clear_button</code></td>
428
- <td align="left" style="width: 25%;">
429
-
430
- ```python
431
- bool | None
432
- ```
433
-
434
- </td>
435
- <td align="left"><code>True</code></td>
436
- <td align="left">If True, will show a clear button.</td>
437
- </tr>
438
- </tbody></table>
439
-
440
-
441
- ### Events
442
-
443
- | name | description |
444
- |:-----|:------------|
445
- | `clear` | This listener is triggered when the user clears the image_annotator using the X button for the component. |
446
- | `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. |
447
- | `upload` | This listener is triggered when the user uploads a file into the image_annotator. |
448
-
449
-
450
-
451
- ### User function
452
-
453
- 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).
454
-
455
- - When used as an Input, the component only impacts the input signature of the user function.
456
- - When used as an output, the component only impacts the return signature of the user function.
457
-
458
- The code snippet below is accurate in cases where the component is used as both an input and an output.
459
-
460
- - **As output:** Is passed, a dict with the image and boxes or None.
461
- - **As input:** Should return, a dict with an image and an optional list of boxes or None.
462
-
463
- ```python
464
- def predict(
465
- value: dict | None
466
- ) -> dict | None:
467
- return value
468
- ```
469
-
 
1
 
2
+ ---
3
+ tags: [gradio-custom-component,gradio-template-Image,bounding box,annotator,annotate,boxes]
4
+ title: gradio_image_annotation V0.0.7
5
+ colorFrom: purple
6
+ colorTo: green
7
+ sdk: docker
8
+ pinned: false
9
+ license: apache-2.0
10
+ ---
11
 
 
12
 
13
+ # Name: gradio_image_annotation
14
 
15
+ Description: A Gradio component that can be used to annotate images with bounding boxes.
 
 
16
 
17
+ Install with: pip install gradio_image_annotation
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
requirements.txt CHANGED
@@ -1 +1 @@
1
- gradio_image_annotation==0.0.6
 
1
+ gradio_image_annotation-0.0.7-py3-none-any.whl