gradio-pr-bot commited on
Commit
9182e73
·
verified ·
1 Parent(s): ec7221e

Upload folder using huggingface_hub

Browse files
6.13.1/annotatedimage/Index.svelte ADDED
@@ -0,0 +1,195 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ on:fullscreen={({ detail }) => {
78
+ fullscreen = detail;
79
+ }}
80
+ />
81
+ {/if}
82
+ </IconButtonWrapper>
83
+
84
+ <img
85
+ class="base-image"
86
+ class:fit-height={gradio.props.height && !fullscreen}
87
+ src={gradio.props.value ? gradio.props.value.image.url : null}
88
+ alt="the base file that is annotated"
89
+ />
90
+ {#each gradio.props.value ? gradio.props.value.annotations : [] as ann, i}
91
+ <img
92
+ alt="segmentation mask identifying {gradio.shared
93
+ .label} within the uploaded file"
94
+ class="mask fit-height"
95
+ class:fit-height={!fullscreen}
96
+ class:active={active == ann.label}
97
+ class:inactive={active != ann.label && active != null}
98
+ src={ann.image.url}
99
+ style={gradio.props.color_map && ann.label in gradio.props.color_map
100
+ ? null
101
+ : `filter: hue-rotate(${Math.round(
102
+ (i * 360) / (gradio.props.value?.annotations.length ?? 1)
103
+ )}deg);`}
104
+ />
105
+ {/each}
106
+ </div>
107
+ {#if gradio.props.show_legend && gradio.props.value}
108
+ <div class="legend">
109
+ {#each gradio.props.value.annotations as ann, i}
110
+ <button
111
+ class="legend-item"
112
+ style="background-color: {gradio.props.color_map &&
113
+ ann.label in gradio.props.color_map
114
+ ? gradio.props.color_map[ann.label] + '88'
115
+ : `hsla(${Math.round(
116
+ (i * 360) / gradio.props.value.annotations.length
117
+ )}, 100%, 50%, 0.3)`}"
118
+ on:mouseover={() => handle_mouseover(ann.label)}
119
+ on:focus={() => handle_mouseover(ann.label)}
120
+ on:mouseout={() => handle_mouseout()}
121
+ on:blur={() => handle_mouseout()}
122
+ on:click={() => handle_click(i, ann.label)}
123
+ >
124
+ {ann.label}
125
+ </button>
126
+ {/each}
127
+ </div>
128
+ {/if}
129
+ {/if}
130
+ </div>
131
+ </Block>
132
+
133
+ <style>
134
+ .base-image {
135
+ display: block;
136
+ width: 100%;
137
+ height: auto;
138
+ }
139
+ .container {
140
+ display: flex;
141
+ position: relative;
142
+ flex-direction: column;
143
+ justify-content: center;
144
+ align-items: center;
145
+ width: var(--size-full);
146
+ height: var(--size-full);
147
+ }
148
+ .image-container {
149
+ position: relative;
150
+ top: 0;
151
+ left: 0;
152
+ flex-grow: 1;
153
+ width: 100%;
154
+ overflow: hidden;
155
+ }
156
+ .fit-height {
157
+ top: 0;
158
+ left: 0;
159
+ width: 100%;
160
+ height: 100%;
161
+ object-fit: contain;
162
+ }
163
+ .mask {
164
+ opacity: 0.85;
165
+ transition: all 0.2s ease-in-out;
166
+ position: absolute;
167
+ }
168
+ .image-container:hover .mask {
169
+ opacity: 0.3;
170
+ }
171
+ .mask.active {
172
+ opacity: 1;
173
+ }
174
+ .mask.inactive {
175
+ opacity: 0;
176
+ }
177
+ .legend {
178
+ display: flex;
179
+ flex-direction: row;
180
+ flex-wrap: wrap;
181
+ align-content: center;
182
+ justify-content: center;
183
+ align-items: center;
184
+ gap: var(--spacing-sm);
185
+ padding: var(--spacing-sm);
186
+ }
187
+ .legend-item {
188
+ display: flex;
189
+ flex-direction: row;
190
+ align-items: center;
191
+ cursor: pointer;
192
+ border-radius: var(--radius-sm);
193
+ padding: var(--spacing-sm);
194
+ }
195
+ </style>
6.13.1/annotatedimage/package.json ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "@gradio/annotatedimage",
3
+ "version": "0.11.8",
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.13.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
+ }