gradio-pr-bot commited on
Commit
eceb097
·
verified ·
1 Parent(s): 03c65bd

Upload folder using huggingface_hub

Browse files
6.3.0/annotatedimage/Index.svelte ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 old_value = $state(gradio.props.value);
19
+ let active: string | null = $state(null);
20
+ let image_container: HTMLElement;
21
+ let fullscreen = $state(false);
22
+ let label = $derived(
23
+ gradio.shared.label || gradio.i18n("annotated_image.annotated_image")
24
+ );
25
+
26
+ $effect(() => {
27
+ if (old_value != gradio.props.value) {
28
+ old_value = gradio.props.value;
29
+ gradio.dispatch("change");
30
+ }
31
+ });
32
+
33
+ function handle_mouseover(_label: string): void {
34
+ active = _label;
35
+ }
36
+
37
+ function handle_mouseout(): void {
38
+ active = null;
39
+ }
40
+
41
+ function handle_click(i: number, value: string): void {
42
+ gradio.dispatch("select", {
43
+ value: value,
44
+ index: i
45
+ });
46
+ }
47
+ </script>
48
+
49
+ <Block
50
+ visible={gradio.shared.visible}
51
+ elem_id={gradio.shared.elem_id}
52
+ elem_classes={gradio.shared.elem_classes}
53
+ padding={false}
54
+ height={gradio.props.height}
55
+ width={gradio.props.width}
56
+ allow_overflow={false}
57
+ container={gradio.shared.container}
58
+ scale={gradio.shared.scale}
59
+ min_width={gradio.shared.min_width}
60
+ bind:fullscreen
61
+ >
62
+ <StatusTracker
63
+ autoscroll={gradio.shared.autoscroll}
64
+ i18n={gradio.i18n}
65
+ {...gradio.shared.loading_status}
66
+ />
67
+ <BlockLabel show_label={gradio.shared.show_label} Icon={Image} {label} />
68
+
69
+ <div class="container">
70
+ {#if gradio.props.value == null}
71
+ <Empty size="large" unpadded_box={true}><Image /></Empty>
72
+ {:else}
73
+ <div class="image-container" bind:this={image_container}>
74
+ <IconButtonWrapper
75
+ buttons={gradio.props.buttons || []}
76
+ on_custom_button_click={(id) => {
77
+ gradio.dispatch("custom_button_click", { id });
78
+ }}
79
+ >
80
+ {#if (gradio.props.buttons || []).some((btn) => typeof btn === "string" && btn === "fullscreen")}
81
+ <FullscreenButton
82
+ {fullscreen}
83
+ on:fullscreen={({ detail }) => {
84
+ fullscreen = detail;
85
+ }}
86
+ />
87
+ {/if}
88
+ </IconButtonWrapper>
89
+
90
+ <img
91
+ class="base-image"
92
+ class:fit-height={gradio.props.height && !fullscreen}
93
+ src={gradio.props.value ? gradio.props.value.image.url : null}
94
+ alt="the base file that is annotated"
95
+ />
96
+ {#each gradio.props.value ? gradio.props.value.annotations : [] as ann, i}
97
+ <img
98
+ alt="segmentation mask identifying {gradio.shared
99
+ .label} within the uploaded file"
100
+ class="mask fit-height"
101
+ class:fit-height={!fullscreen}
102
+ class:active={active == ann.label}
103
+ class:inactive={active != ann.label && active != null}
104
+ src={ann.image.url}
105
+ style={gradio.props.color_map && ann.label in gradio.props.color_map
106
+ ? null
107
+ : `filter: hue-rotate(${Math.round(
108
+ (i * 360) / (gradio.props.value?.annotations.length ?? 1)
109
+ )}deg);`}
110
+ />
111
+ {/each}
112
+ </div>
113
+ {#if gradio.props.show_legend && gradio.props.value}
114
+ <div class="legend">
115
+ {#each gradio.props.value.annotations as ann, i}
116
+ <button
117
+ class="legend-item"
118
+ style="background-color: {gradio.props.color_map &&
119
+ ann.label in gradio.props.color_map
120
+ ? gradio.props.color_map[ann.label] + '88'
121
+ : `hsla(${Math.round(
122
+ (i * 360) / gradio.props.value.annotations.length
123
+ )}, 100%, 50%, 0.3)`}"
124
+ on:mouseover={() => handle_mouseover(ann.label)}
125
+ on:focus={() => handle_mouseover(ann.label)}
126
+ on:mouseout={() => handle_mouseout()}
127
+ on:blur={() => handle_mouseout()}
128
+ on:click={() => handle_click(i, ann.label)}
129
+ >
130
+ {ann.label}
131
+ </button>
132
+ {/each}
133
+ </div>
134
+ {/if}
135
+ {/if}
136
+ </div>
137
+ </Block>
138
+
139
+ <style>
140
+ .base-image {
141
+ display: block;
142
+ width: 100%;
143
+ height: auto;
144
+ }
145
+ .container {
146
+ display: flex;
147
+ position: relative;
148
+ flex-direction: column;
149
+ justify-content: center;
150
+ align-items: center;
151
+ width: var(--size-full);
152
+ height: var(--size-full);
153
+ }
154
+ .image-container {
155
+ position: relative;
156
+ top: 0;
157
+ left: 0;
158
+ flex-grow: 1;
159
+ width: 100%;
160
+ overflow: hidden;
161
+ }
162
+ .fit-height {
163
+ top: 0;
164
+ left: 0;
165
+ width: 100%;
166
+ height: 100%;
167
+ object-fit: contain;
168
+ }
169
+ .mask {
170
+ opacity: 0.85;
171
+ transition: all 0.2s ease-in-out;
172
+ position: absolute;
173
+ }
174
+ .image-container:hover .mask {
175
+ opacity: 0.3;
176
+ }
177
+ .mask.active {
178
+ opacity: 1;
179
+ }
180
+ .mask.inactive {
181
+ opacity: 0;
182
+ }
183
+ .legend {
184
+ display: flex;
185
+ flex-direction: row;
186
+ flex-wrap: wrap;
187
+ align-content: center;
188
+ justify-content: center;
189
+ align-items: center;
190
+ gap: var(--spacing-sm);
191
+ padding: var(--spacing-sm);
192
+ }
193
+ .legend-item {
194
+ display: flex;
195
+ flex-direction: row;
196
+ align-items: center;
197
+ cursor: pointer;
198
+ border-radius: var(--radius-sm);
199
+ padding: var(--spacing-sm);
200
+ }
201
+ </style>
6.3.0/annotatedimage/package.json ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "@gradio/annotatedimage",
3
+ "version": "0.11.0",
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.43.4"
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.3.0/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
+ }