edgargg commited on
Commit
e94d15e
1 Parent(s): 0dcdcc2

Upload folder using huggingface_hub

Browse files
README.md CHANGED
@@ -1,19 +1,3 @@
1
- ---
2
- tags:
3
- - gradio-custom-component
4
- - gradio-template-Image
5
- - bounding box
6
- - annotator
7
- - annotate
8
- - boxes
9
- title: gradio_image_annotation V0.2.2
10
- colorFrom: yellow
11
- colorTo: green
12
- sdk: docker
13
- pinned: false
14
- license: apache-2.0
15
- short_description: A Gradio component for image annotation
16
- ---
17
 
18
  # `gradio_image_annotation`
19
  <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>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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>
app.py CHANGED
@@ -24,18 +24,32 @@ example_annotation = {
24
  ]
25
  }
26
 
27
- example_crop = {
28
- "image": "https://raw.githubusercontent.com/gradio-app/gradio/main/guides/assets/logo.png",
29
- "boxes": [
30
- {
31
- "xmin": 30,
32
- "ymin": 70,
33
- "xmax": 530,
34
- "ymax": 500,
35
- "color": (100, 200, 255)
36
- }
37
- ]
38
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
 
40
 
41
  def crop(annotations):
@@ -66,7 +80,7 @@ with gr.Blocks() as demo:
66
  with gr.Tab("Crop"):
67
  with gr.Row():
68
  annotator_crop = image_annotator(
69
- example_crop,
70
  image_type="numpy",
71
  disable_edit_boxes=True,
72
  single_box=True,
@@ -75,6 +89,7 @@ with gr.Blocks() as demo:
75
  button_crop = gr.Button("Crop")
76
  button_crop.click(crop, annotator_crop, image_crop)
77
 
 
78
 
79
  if __name__ == "__main__":
80
  demo.launch()
 
24
  ]
25
  }
26
 
27
+ examples_crop = [
28
+ {
29
+ "image": "https://raw.githubusercontent.com/gradio-app/gradio/main/guides/assets/logo.png",
30
+ "boxes": [
31
+ {
32
+ "xmin": 30,
33
+ "ymin": 70,
34
+ "xmax": 530,
35
+ "ymax": 500,
36
+ "color": (100, 200, 255),
37
+ }
38
+ ],
39
+ },
40
+ {
41
+ "image": "https://gradio-builds.s3.amazonaws.com/demo-files/base.png",
42
+ "boxes": [
43
+ {
44
+ "xmin": 636,
45
+ "ymin": 575,
46
+ "xmax": 801,
47
+ "ymax": 697,
48
+ "color": (255, 0, 0),
49
+ },
50
+ ],
51
+ },
52
+ ]
53
 
54
 
55
  def crop(annotations):
 
80
  with gr.Tab("Crop"):
81
  with gr.Row():
82
  annotator_crop = image_annotator(
83
+ examples_crop[0],
84
  image_type="numpy",
85
  disable_edit_boxes=True,
86
  single_box=True,
 
89
  button_crop = gr.Button("Crop")
90
  button_crop.click(crop, annotator_crop, image_crop)
91
 
92
+ gr.Examples(examples_crop, annotator_crop)
93
 
94
  if __name__ == "__main__":
95
  demo.launch()
space.py CHANGED
@@ -1,3 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
 
2
  import gradio as gr
3
  from app import demo as app
 
1
+ ---
2
+ tags:
3
+ - gradio-custom-component
4
+ - gradio-template-Image
5
+ - bounding box
6
+ - annotator
7
+ - annotate
8
+ - boxes
9
+ title: gradio_image_annotation V0.2.2
10
+ colorFrom: yellow
11
+ colorTo: green
12
+ sdk: docker
13
+ pinned: false
14
+ license: apache-2.0
15
+ short_description: A Gradio component for image annotation
16
+ ---
17
 
18
  import gradio as gr
19
  from app import demo as app
src/backend/gradio_image_annotation/image_annotator.py CHANGED
@@ -298,6 +298,25 @@ class image_annotator(Component):
298
 
299
  return AnnotatedImageData(image=image, boxes=boxes)
300
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
301
  def example_inputs(self) -> Any:
302
  return {
303
  "image": "https://raw.githubusercontent.com/gradio-app/gradio/main/guides/assets/logo.png",
 
298
 
299
  return AnnotatedImageData(image=image, boxes=boxes)
300
 
301
+ def process_example(self, value: dict | None) -> FileData | None:
302
+ if value is None:
303
+ return None
304
+ if not isinstance(value, dict):
305
+ raise ValueError(f"``value`` must be a dict. Got {type(value)}")
306
+
307
+ image = value.setdefault("image", None)
308
+ if image is not None:
309
+ if isinstance(image, str) and image.lower().endswith(".svg"):
310
+ image = FileData(path=image, orig_name=Path(image).name)
311
+ else:
312
+ saved = image_utils.save_image(image, self.GRADIO_CACHE)
313
+ orig_name = Path(saved).name if Path(saved).exists() else None
314
+ image = FileData(path=saved, orig_name=orig_name)
315
+ else:
316
+ raise ValueError(f"An image must be provided. Got {value}")
317
+
318
+ return image
319
+
320
  def example_inputs(self) -> Any:
321
  return {
322
  "image": "https://raw.githubusercontent.com/gradio-app/gradio/main/guides/assets/logo.png",
src/demo/app.py CHANGED
@@ -24,18 +24,32 @@ example_annotation = {
24
  ]
25
  }
26
 
27
- example_crop = {
28
- "image": "https://raw.githubusercontent.com/gradio-app/gradio/main/guides/assets/logo.png",
29
- "boxes": [
30
- {
31
- "xmin": 30,
32
- "ymin": 70,
33
- "xmax": 530,
34
- "ymax": 500,
35
- "color": (100, 200, 255)
36
- }
37
- ]
38
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
 
40
 
41
  def crop(annotations):
@@ -66,7 +80,7 @@ with gr.Blocks() as demo:
66
  with gr.Tab("Crop"):
67
  with gr.Row():
68
  annotator_crop = image_annotator(
69
- example_crop,
70
  image_type="numpy",
71
  disable_edit_boxes=True,
72
  single_box=True,
@@ -75,6 +89,7 @@ with gr.Blocks() as demo:
75
  button_crop = gr.Button("Crop")
76
  button_crop.click(crop, annotator_crop, image_crop)
77
 
 
78
 
79
  if __name__ == "__main__":
80
  demo.launch()
 
24
  ]
25
  }
26
 
27
+ examples_crop = [
28
+ {
29
+ "image": "https://raw.githubusercontent.com/gradio-app/gradio/main/guides/assets/logo.png",
30
+ "boxes": [
31
+ {
32
+ "xmin": 30,
33
+ "ymin": 70,
34
+ "xmax": 530,
35
+ "ymax": 500,
36
+ "color": (100, 200, 255),
37
+ }
38
+ ],
39
+ },
40
+ {
41
+ "image": "https://gradio-builds.s3.amazonaws.com/demo-files/base.png",
42
+ "boxes": [
43
+ {
44
+ "xmin": 636,
45
+ "ymin": 575,
46
+ "xmax": 801,
47
+ "ymax": 697,
48
+ "color": (255, 0, 0),
49
+ },
50
+ ],
51
+ },
52
+ ]
53
 
54
 
55
  def crop(annotations):
 
80
  with gr.Tab("Crop"):
81
  with gr.Row():
82
  annotator_crop = image_annotator(
83
+ examples_crop[0],
84
  image_type="numpy",
85
  disable_edit_boxes=True,
86
  single_box=True,
 
89
  button_crop = gr.Button("Crop")
90
  button_crop.click(crop, annotator_crop, image_crop)
91
 
92
+ gr.Examples(examples_crop, annotator_crop)
93
 
94
  if __name__ == "__main__":
95
  demo.launch()
src/demo/space.py CHANGED
@@ -1,3 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
 
2
  import gradio as gr
3
  from app import demo as app
 
1
+ ---
2
+ tags:
3
+ - gradio-custom-component
4
+ - gradio-template-Image
5
+ - bounding box
6
+ - annotator
7
+ - annotate
8
+ - boxes
9
+ title: gradio_image_annotation V0.2.2
10
+ colorFrom: yellow
11
+ colorTo: green
12
+ sdk: docker
13
+ pinned: false
14
+ license: apache-2.0
15
+ short_description: A Gradio component for image annotation
16
+ ---
17
 
18
  import gradio as gr
19
  from app import demo as app
src/frontend/Example.svelte CHANGED
@@ -1,9 +1,7 @@
1
  <script lang="ts">
2
- import Image from "./shared/ImageCanvas.svelte";
3
  import type { FileData } from "@gradio/client";
4
 
5
  export let value: null | FileData;
6
- export let samples_dir: string;
7
  export let type: "gallery" | "table";
8
  export let selected = false;
9
  </script>
@@ -16,7 +14,7 @@
16
  class:border={value}
17
  >
18
  {#if value}
19
- <Image src={samples_dir + value.path} alt="" />
20
  {/if}
21
  </div>
22
 
 
1
  <script lang="ts">
 
2
  import type { FileData } from "@gradio/client";
3
 
4
  export let value: null | FileData;
 
5
  export let type: "gallery" | "table";
6
  export let selected = false;
7
  </script>
 
14
  class:border={value}
15
  >
16
  {#if value}
17
+ <img src={value.url} alt="" />
18
  {/if}
19
  </div>
20