gradio-pr-bot commited on
Commit
d8b9af6
·
verified ·
1 Parent(s): 0607ee7

Upload folder using huggingface_hub

Browse files
6.23.1/annotatedimage/Index.svelte ADDED
@@ -0,0 +1,193 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import {
3
+ Block,
4
+ BlockLabel,
5
+ Empty,
6
+ IconButtonWrapper,
7
+ FullscreenButton
8
+ } from "@gradio/atoms";
9
+ import type { CustomButton as CustomButtonType } from "@gradio/utils";
10
+ import { Image } from "@gradio/icons";
11
+ import { StatusTracker } from "@gradio/statustracker";
12
+ import { Gradio } from "@gradio/utils";
13
+ import type { AnnotatedImageProps, AnnotatedImageEvents } from "./types";
14
+
15
+ const props = $props();
16
+ const gradio = new Gradio<AnnotatedImageEvents, AnnotatedImageProps>(props);
17
+
18
+ let active: string | null = $state(null);
19
+ let image_container: HTMLElement;
20
+ let fullscreen = $state(false);
21
+ let label = $derived(
22
+ gradio.shared.label || gradio.i18n("annotated_image.annotated_image")
23
+ );
24
+
25
+ gradio.watch_for_change();
26
+
27
+ function handle_mouseover(_label: string): void {
28
+ active = _label;
29
+ }
30
+
31
+ function handle_mouseout(): void {
32
+ active = null;
33
+ }
34
+
35
+ function handle_click(i: number, value: string): void {
36
+ gradio.dispatch("select", {
37
+ value: value,
38
+ index: i
39
+ });
40
+ }
41
+ </script>
42
+
43
+ <Block
44
+ visible={gradio.shared.visible}
45
+ elem_id={gradio.shared.elem_id}
46
+ elem_classes={gradio.shared.elem_classes}
47
+ padding={false}
48
+ height={gradio.props.height}
49
+ width={gradio.props.width}
50
+ allow_overflow={false}
51
+ container={gradio.shared.container}
52
+ scale={gradio.shared.scale}
53
+ min_width={gradio.shared.min_width}
54
+ bind:fullscreen
55
+ >
56
+ <StatusTracker
57
+ autoscroll={gradio.shared.autoscroll}
58
+ i18n={gradio.i18n}
59
+ {...gradio.shared.loading_status}
60
+ />
61
+ <BlockLabel show_label={gradio.shared.show_label} Icon={Image} {label} />
62
+
63
+ <div class="container">
64
+ {#if gradio.props.value == null}
65
+ <Empty size="large" unpadded_box={true}><Image /></Empty>
66
+ {:else}
67
+ <div class="image-container" bind:this={image_container}>
68
+ <IconButtonWrapper
69
+ buttons={gradio.props.buttons || []}
70
+ on_custom_button_click={(id) => {
71
+ gradio.dispatch("custom_button_click", { id });
72
+ }}
73
+ >
74
+ {#if (gradio.props.buttons || []).some((btn) => typeof btn === "string" && btn === "fullscreen")}
75
+ <FullscreenButton
76
+ {fullscreen}
77
+ onclick={(fs) => (fullscreen = fs)}
78
+ />
79
+ {/if}
80
+ </IconButtonWrapper>
81
+
82
+ <img
83
+ class="base-image"
84
+ class:fit-height={gradio.props.height && !fullscreen}
85
+ src={gradio.props.value ? gradio.props.value.image.url : null}
86
+ alt="the base file that is annotated"
87
+ />
88
+ {#each gradio.props.value ? gradio.props.value.annotations : [] as ann, i}
89
+ <img
90
+ alt="segmentation mask identifying {gradio.shared
91
+ .label} within the uploaded file"
92
+ class="mask fit-height"
93
+ class:fit-height={!fullscreen}
94
+ class:active={active == ann.label}
95
+ class:inactive={active != ann.label && active != null}
96
+ src={ann.image.url}
97
+ style={gradio.props.color_map && ann.label in gradio.props.color_map
98
+ ? null
99
+ : `filter: hue-rotate(${Math.round(
100
+ (i * 360) / (gradio.props.value?.annotations.length ?? 1)
101
+ )}deg);`}
102
+ />
103
+ {/each}
104
+ </div>
105
+ {#if gradio.props.show_legend && gradio.props.value}
106
+ <div class="legend">
107
+ {#each gradio.props.value.annotations as ann, i}
108
+ <button
109
+ class="legend-item"
110
+ style="background-color: {gradio.props.color_map &&
111
+ ann.label in gradio.props.color_map
112
+ ? gradio.props.color_map[ann.label] + '88'
113
+ : `hsla(${Math.round(
114
+ (i * 360) / gradio.props.value.annotations.length
115
+ )}, 100%, 50%, 0.3)`}"
116
+ onmouseover={() => handle_mouseover(ann.label)}
117
+ onfocus={() => handle_mouseover(ann.label)}
118
+ onmouseout={() => handle_mouseout()}
119
+ onblur={() => handle_mouseout()}
120
+ onclick={() => handle_click(i, ann.label)}
121
+ >
122
+ {ann.label}
123
+ </button>
124
+ {/each}
125
+ </div>
126
+ {/if}
127
+ {/if}
128
+ </div>
129
+ </Block>
130
+
131
+ <style>
132
+ .base-image {
133
+ display: block;
134
+ width: 100%;
135
+ height: auto;
136
+ }
137
+ .container {
138
+ display: flex;
139
+ position: relative;
140
+ flex-direction: column;
141
+ justify-content: center;
142
+ align-items: center;
143
+ width: var(--size-full);
144
+ height: var(--size-full);
145
+ }
146
+ .image-container {
147
+ position: relative;
148
+ top: 0;
149
+ left: 0;
150
+ flex-grow: 1;
151
+ width: 100%;
152
+ overflow: hidden;
153
+ }
154
+ .fit-height {
155
+ top: 0;
156
+ left: 0;
157
+ width: 100%;
158
+ height: 100%;
159
+ object-fit: contain;
160
+ }
161
+ .mask {
162
+ opacity: 0.85;
163
+ transition: all 0.2s ease-in-out;
164
+ position: absolute;
165
+ }
166
+ .image-container:hover .mask {
167
+ opacity: 0.3;
168
+ }
169
+ .mask.active {
170
+ opacity: 1;
171
+ }
172
+ .mask.inactive {
173
+ opacity: 0;
174
+ }
175
+ .legend {
176
+ display: flex;
177
+ flex-direction: row;
178
+ flex-wrap: wrap;
179
+ align-content: center;
180
+ justify-content: center;
181
+ align-items: center;
182
+ gap: var(--spacing-sm);
183
+ padding: var(--spacing-sm);
184
+ }
185
+ .legend-item {
186
+ display: flex;
187
+ flex-direction: row;
188
+ align-items: center;
189
+ cursor: pointer;
190
+ border-radius: var(--radius-sm);
191
+ padding: var(--spacing-sm);
192
+ }
193
+ </style>
6.23.1/annotatedimage/package.json ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "@gradio/annotatedimage",
3
+ "version": "0.12.2",
4
+ "description": "Gradio UI packages",
5
+ "type": "module",
6
+ "author": "",
7
+ "license": "ISC",
8
+ "private": false,
9
+ "main_changeset": true,
10
+ "exports": {
11
+ ".": {
12
+ "gradio": "./Index.svelte",
13
+ "svelte": "./dist/Index.svelte",
14
+ "types": "./dist/Index.svelte.d.ts"
15
+ },
16
+ "./package.json": "./package.json"
17
+ },
18
+ "devDependencies": {
19
+ "@gradio/preview": "workspace:^"
20
+ },
21
+ "peerDependencies": {
22
+ "svelte": "^5.48.0"
23
+ },
24
+ "dependencies": {
25
+ "@gradio/atoms": "workspace:^",
26
+ "@gradio/icons": "workspace:^",
27
+ "@gradio/statustracker": "workspace:^",
28
+ "@gradio/upload": "workspace:^",
29
+ "@gradio/utils": "workspace:^",
30
+ "@gradio/client": "workspace:^"
31
+ },
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "git+https://github.com/gradio-app/gradio.git",
35
+ "directory": "js/annotatedimage"
36
+ }
37
+ }
6.23.1/annotatedimage/types.ts ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type { FileData } from "@gradio/client";
2
+ import type { CustomButton } from "@gradio/utils";
3
+
4
+ export interface Annotation {
5
+ image: FileData;
6
+ label: string;
7
+ }
8
+
9
+ export interface AnnotatedImageValue {
10
+ image: FileData;
11
+ annotations: Annotation[];
12
+ }
13
+
14
+ export interface AnnotatedImageProps {
15
+ value: AnnotatedImageValue | null;
16
+ show_legend: boolean;
17
+ height: number | undefined;
18
+ width: number | undefined;
19
+ color_map: Record<string, string>;
20
+ buttons: (string | CustomButton)[];
21
+ }
22
+
23
+ export interface AnnotatedImageEvents {
24
+ change: never;
25
+ select: { index: number; value: string };
26
+ custom_button_click: { id: number };
27
+ }