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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import type { Gradio, SelectData } from "@gradio/utils";
|
| 3 |
+
|
| 4 |
+
import {
|
| 5 |
+
Block,
|
| 6 |
+
BlockLabel,
|
| 7 |
+
Empty,
|
| 8 |
+
IconButtonWrapper,
|
| 9 |
+
FullscreenButton
|
| 10 |
+
} from "@gradio/atoms";
|
| 11 |
+
import { Image } from "@gradio/icons";
|
| 12 |
+
import { StatusTracker } from "@gradio/statustracker";
|
| 13 |
+
import type { LoadingStatus } from "@gradio/statustracker";
|
| 14 |
+
import { type FileData } from "@gradio/client";
|
| 15 |
+
|
| 16 |
+
export let elem_id = "";
|
| 17 |
+
export let elem_classes: string[] = [];
|
| 18 |
+
export let visible: boolean | "hidden" = true;
|
| 19 |
+
export let value: {
|
| 20 |
+
image: FileData;
|
| 21 |
+
annotations: { image: FileData; label: string }[] | [];
|
| 22 |
+
} | null = null;
|
| 23 |
+
let old_value: {
|
| 24 |
+
image: FileData;
|
| 25 |
+
annotations: { image: FileData; label: string }[] | [];
|
| 26 |
+
} | null = null;
|
| 27 |
+
let _value: {
|
| 28 |
+
image: FileData;
|
| 29 |
+
annotations: { image: FileData; label: string }[];
|
| 30 |
+
} | null = null;
|
| 31 |
+
export let gradio: Gradio<{
|
| 32 |
+
change: undefined;
|
| 33 |
+
select: SelectData;
|
| 34 |
+
}>;
|
| 35 |
+
export let label = gradio.i18n("annotated_image.annotated_image");
|
| 36 |
+
export let show_label = true;
|
| 37 |
+
export let show_legend = true;
|
| 38 |
+
export let height: number | undefined;
|
| 39 |
+
export let width: number | undefined;
|
| 40 |
+
export let color_map: Record<string, string>;
|
| 41 |
+
export let container = true;
|
| 42 |
+
export let scale: number | null = null;
|
| 43 |
+
export let min_width: number | undefined = undefined;
|
| 44 |
+
let active: string | null = null;
|
| 45 |
+
export let loading_status: LoadingStatus;
|
| 46 |
+
export let show_fullscreen_button = true;
|
| 47 |
+
|
| 48 |
+
let image_container: HTMLElement;
|
| 49 |
+
let fullscreen = false;
|
| 50 |
+
|
| 51 |
+
// `value` can be updated before the Promises from `resolve_wasm_src` are resolved.
|
| 52 |
+
// In such a case, the resolved values for the old `value` have to be discarded,
|
| 53 |
+
// This variable `latest_promise` is used to pick up only the values resolved for the latest `value`.
|
| 54 |
+
let latest_promise: Promise<unknown> | null = null;
|
| 55 |
+
$: {
|
| 56 |
+
if (value !== old_value) {
|
| 57 |
+
old_value = value;
|
| 58 |
+
gradio.dispatch("change");
|
| 59 |
+
}
|
| 60 |
+
if (value) {
|
| 61 |
+
const normalized_value = {
|
| 62 |
+
image: value.image as FileData,
|
| 63 |
+
annotations: value.annotations.map((ann) => ({
|
| 64 |
+
image: ann.image as FileData,
|
| 65 |
+
label: ann.label
|
| 66 |
+
}))
|
| 67 |
+
};
|
| 68 |
+
_value = normalized_value;
|
| 69 |
+
} else {
|
| 70 |
+
_value = null;
|
| 71 |
+
}
|
| 72 |
+
}
|
| 73 |
+
function handle_mouseover(_label: string): void {
|
| 74 |
+
active = _label;
|
| 75 |
+
}
|
| 76 |
+
function handle_mouseout(): void {
|
| 77 |
+
active = null;
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
function handle_click(i: number, value: string): void {
|
| 81 |
+
gradio.dispatch("select", {
|
| 82 |
+
value: label,
|
| 83 |
+
index: i
|
| 84 |
+
});
|
| 85 |
+
}
|
| 86 |
+
</script>
|
| 87 |
+
|
| 88 |
+
<Block
|
| 89 |
+
{visible}
|
| 90 |
+
{elem_id}
|
| 91 |
+
{elem_classes}
|
| 92 |
+
padding={false}
|
| 93 |
+
{height}
|
| 94 |
+
{width}
|
| 95 |
+
allow_overflow={false}
|
| 96 |
+
{container}
|
| 97 |
+
{scale}
|
| 98 |
+
{min_width}
|
| 99 |
+
bind:fullscreen
|
| 100 |
+
>
|
| 101 |
+
<StatusTracker
|
| 102 |
+
autoscroll={gradio.autoscroll}
|
| 103 |
+
i18n={gradio.i18n}
|
| 104 |
+
{...loading_status}
|
| 105 |
+
/>
|
| 106 |
+
<BlockLabel
|
| 107 |
+
{show_label}
|
| 108 |
+
Icon={Image}
|
| 109 |
+
label={label || gradio.i18n("image.image")}
|
| 110 |
+
/>
|
| 111 |
+
|
| 112 |
+
<div class="container">
|
| 113 |
+
{#if _value == null}
|
| 114 |
+
<Empty size="large" unpadded_box={true}><Image /></Empty>
|
| 115 |
+
{:else}
|
| 116 |
+
<div class="image-container" bind:this={image_container}>
|
| 117 |
+
<IconButtonWrapper>
|
| 118 |
+
{#if show_fullscreen_button}
|
| 119 |
+
<FullscreenButton
|
| 120 |
+
{fullscreen}
|
| 121 |
+
on:fullscreen={({ detail }) => {
|
| 122 |
+
fullscreen = detail;
|
| 123 |
+
}}
|
| 124 |
+
/>
|
| 125 |
+
{/if}
|
| 126 |
+
</IconButtonWrapper>
|
| 127 |
+
|
| 128 |
+
<img
|
| 129 |
+
class="base-image"
|
| 130 |
+
class:fit-height={height && !fullscreen}
|
| 131 |
+
src={_value ? _value.image.url : null}
|
| 132 |
+
alt="the base file that is annotated"
|
| 133 |
+
/>
|
| 134 |
+
{#each _value ? _value?.annotations : [] as ann, i}
|
| 135 |
+
<img
|
| 136 |
+
alt="segmentation mask identifying {label} within the uploaded file"
|
| 137 |
+
class="mask fit-height"
|
| 138 |
+
class:fit-height={!fullscreen}
|
| 139 |
+
class:active={active == ann.label}
|
| 140 |
+
class:inactive={active != ann.label && active != null}
|
| 141 |
+
src={ann.image.url}
|
| 142 |
+
style={color_map && ann.label in color_map
|
| 143 |
+
? null
|
| 144 |
+
: `filter: hue-rotate(${Math.round(
|
| 145 |
+
(i * 360) / _value?.annotations.length
|
| 146 |
+
)}deg);`}
|
| 147 |
+
/>
|
| 148 |
+
{/each}
|
| 149 |
+
</div>
|
| 150 |
+
{#if show_legend && _value}
|
| 151 |
+
<div class="legend">
|
| 152 |
+
{#each _value.annotations as ann, i}
|
| 153 |
+
<button
|
| 154 |
+
class="legend-item"
|
| 155 |
+
style="background-color: {color_map && ann.label in color_map
|
| 156 |
+
? color_map[ann.label] + '88'
|
| 157 |
+
: `hsla(${Math.round(
|
| 158 |
+
(i * 360) / _value.annotations.length
|
| 159 |
+
)}, 100%, 50%, 0.3)`}"
|
| 160 |
+
on:mouseover={() => handle_mouseover(ann.label)}
|
| 161 |
+
on:focus={() => handle_mouseover(ann.label)}
|
| 162 |
+
on:mouseout={() => handle_mouseout()}
|
| 163 |
+
on:blur={() => handle_mouseout()}
|
| 164 |
+
on:click={() => handle_click(i, ann.label)}
|
| 165 |
+
>
|
| 166 |
+
{ann.label}
|
| 167 |
+
</button>
|
| 168 |
+
{/each}
|
| 169 |
+
</div>
|
| 170 |
+
{/if}
|
| 171 |
+
{/if}
|
| 172 |
+
</div>
|
| 173 |
+
</Block>
|
| 174 |
+
|
| 175 |
+
<style>
|
| 176 |
+
.base-image {
|
| 177 |
+
display: block;
|
| 178 |
+
width: 100%;
|
| 179 |
+
height: auto;
|
| 180 |
+
}
|
| 181 |
+
.container {
|
| 182 |
+
display: flex;
|
| 183 |
+
position: relative;
|
| 184 |
+
flex-direction: column;
|
| 185 |
+
justify-content: center;
|
| 186 |
+
align-items: center;
|
| 187 |
+
width: var(--size-full);
|
| 188 |
+
height: var(--size-full);
|
| 189 |
+
}
|
| 190 |
+
.image-container {
|
| 191 |
+
position: relative;
|
| 192 |
+
top: 0;
|
| 193 |
+
left: 0;
|
| 194 |
+
flex-grow: 1;
|
| 195 |
+
width: 100%;
|
| 196 |
+
overflow: hidden;
|
| 197 |
+
}
|
| 198 |
+
.fit-height {
|
| 199 |
+
top: 0;
|
| 200 |
+
left: 0;
|
| 201 |
+
width: 100%;
|
| 202 |
+
height: 100%;
|
| 203 |
+
object-fit: contain;
|
| 204 |
+
}
|
| 205 |
+
.mask {
|
| 206 |
+
opacity: 0.85;
|
| 207 |
+
transition: all 0.2s ease-in-out;
|
| 208 |
+
position: absolute;
|
| 209 |
+
}
|
| 210 |
+
.image-container:hover .mask {
|
| 211 |
+
opacity: 0.3;
|
| 212 |
+
}
|
| 213 |
+
.mask.active {
|
| 214 |
+
opacity: 1;
|
| 215 |
+
}
|
| 216 |
+
.mask.inactive {
|
| 217 |
+
opacity: 0;
|
| 218 |
+
}
|
| 219 |
+
.legend {
|
| 220 |
+
display: flex;
|
| 221 |
+
flex-direction: row;
|
| 222 |
+
flex-wrap: wrap;
|
| 223 |
+
align-content: center;
|
| 224 |
+
justify-content: center;
|
| 225 |
+
align-items: center;
|
| 226 |
+
gap: var(--spacing-sm);
|
| 227 |
+
padding: var(--spacing-sm);
|
| 228 |
+
}
|
| 229 |
+
.legend-item {
|
| 230 |
+
display: flex;
|
| 231 |
+
flex-direction: row;
|
| 232 |
+
align-items: center;
|
| 233 |
+
cursor: pointer;
|
| 234 |
+
border-radius: var(--radius-sm);
|
| 235 |
+
padding: var(--spacing-sm);
|
| 236 |
+
}
|
| 237 |
+
</style>
|
5.49.1/annotatedimage/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "@gradio/annotatedimage",
|
| 3 |
+
"version": "0.10.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": "^4.0.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 |
+
}
|