gradio-pr-bot commited on
Commit
68e0bb1
·
verified ·
1 Parent(s): d7ce237

Upload folder using huggingface_hub

Browse files
6.4.0/label/Index.svelte ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script context="module" lang="ts">
2
+ export { default as BaseLabel } from "./shared/Label.svelte";
3
+ </script>
4
+
5
+ <script lang="ts">
6
+ import type { LabelProps, LabelEvents } from "./types";
7
+ import { Gradio } from "@gradio/utils";
8
+ import Label from "./shared/Label.svelte";
9
+ import { LineChart as LabelIcon } from "@gradio/icons";
10
+ import { Block, BlockLabel, Empty, IconButtonWrapper } from "@gradio/atoms";
11
+ import { StatusTracker } from "@gradio/statustracker";
12
+ import type { SelectData } from "@gradio/utils";
13
+
14
+ const props = $props();
15
+ const gradio = new Gradio<LabelEvents, LabelProps>(props);
16
+
17
+ let old_value = $state(gradio.props.value);
18
+ let _label = $derived(gradio.props.value.label);
19
+
20
+ $effect(() => {
21
+ if (old_value != gradio.props.value) {
22
+ old_value = gradio.props.value;
23
+ gradio.dispatch("change");
24
+ }
25
+ });
26
+ </script>
27
+
28
+ <Block
29
+ test_id="label"
30
+ visible={gradio.shared.visible}
31
+ elem_id={gradio.shared.elem_id}
32
+ elem_classes={gradio.shared.elem_classes}
33
+ container={gradio.shared.container}
34
+ scale={gradio.shared.scale}
35
+ min_width={gradio.shared.min_width}
36
+ padding={false}
37
+ >
38
+ <StatusTracker
39
+ autoscroll={gradio.shared.autoscroll}
40
+ i18n={gradio.i18n}
41
+ {...gradio.shared.loading_status}
42
+ on_clear_status={() =>
43
+ gradio.dispatch("clear_status", gradio.shared.loading_status)}
44
+ />
45
+ {#if gradio.shared.show_label && gradio.props.buttons && gradio.props.buttons.length > 0}
46
+ <IconButtonWrapper
47
+ buttons={gradio.props.buttons}
48
+ on_custom_button_click={(id) => {
49
+ gradio.dispatch("custom_button_click", { id });
50
+ }}
51
+ />
52
+ {/if}
53
+ {#if gradio.shared.show_label}
54
+ <BlockLabel
55
+ Icon={LabelIcon}
56
+ label={gradio.shared.label || gradio.i18n("label.label")}
57
+ disable={gradio.shared.container === false}
58
+ float={gradio.props.show_heading === true}
59
+ />
60
+ {/if}
61
+ {#if _label !== undefined && _label !== null}
62
+ <Label
63
+ onselect={(detail: SelectData) => gradio.dispatch("select", detail)}
64
+ selectable={gradio.props._selectable}
65
+ value={gradio.props.value}
66
+ color={gradio.props.color}
67
+ show_heading={gradio.props.show_heading}
68
+ />
69
+ {:else}
70
+ <Empty unpadded_box={true}><LabelIcon /></Empty>
71
+ {/if}
72
+ </Block>
6.4.0/label/package.json ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "@gradio/label",
3
+ "version": "0.6.1",
4
+ "description": "Gradio UI packages",
5
+ "type": "module",
6
+ "author": "",
7
+ "license": "ISC",
8
+ "private": false,
9
+ "dependencies": {
10
+ "@gradio/atoms": "workspace:^",
11
+ "@gradio/icons": "workspace:^",
12
+ "@gradio/statustracker": "workspace:^",
13
+ "@gradio/utils": "workspace:^"
14
+ },
15
+ "devDependencies": {
16
+ "@gradio/preview": "workspace:^"
17
+ },
18
+ "main_changeset": true,
19
+ "main": "./Index.svelte",
20
+ "exports": {
21
+ ".": {
22
+ "gradio": "./Index.svelte",
23
+ "svelte": "./dist/Index.svelte",
24
+ "types": "./dist/Index.svelte.d.ts"
25
+ },
26
+ "./package.json": "./package.json"
27
+ },
28
+ "peerDependencies": {
29
+ "svelte": "^5.43.4"
30
+ },
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "git+https://github.com/gradio-app/gradio.git",
34
+ "directory": "js/label"
35
+ }
36
+ }
6.4.0/label/shared/Label.svelte ADDED
@@ -0,0 +1,193 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import type { SelectData } from "@gradio/utils";
3
+
4
+ let {
5
+ value,
6
+ color = undefined,
7
+ selectable = false,
8
+ show_heading = true,
9
+ onselect
10
+ }: {
11
+ value: {
12
+ label?: string;
13
+ confidences?: { label: string; confidence: number }[];
14
+ };
15
+ color?: string | undefined;
16
+ selectable?: boolean;
17
+ show_heading?: boolean;
18
+ onselect?: (detail: SelectData) => void;
19
+ } = $props();
20
+
21
+ function get_aria_referenceable_id(elem_id: string): string {
22
+ // `aria-labelledby` interprets the value as a space-separated id reference list,
23
+ // so each single id should not contain any spaces.
24
+ // Ref: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-labelledby#benefits_and_drawbacks
25
+ return elem_id.replace(/\s/g, "-");
26
+ }
27
+ </script>
28
+
29
+ <div class="container">
30
+ {#if show_heading || !value.confidences}
31
+ <h2
32
+ class="output-class"
33
+ data-testid="label-output-value"
34
+ class:no-confidence={!("confidences" in value)}
35
+ style:background-color={color || "transparent"}
36
+ >
37
+ {value.label}
38
+ </h2>
39
+ {/if}
40
+
41
+ {#if typeof value === "object" && value.confidences}
42
+ {#each value.confidences as confidence_set, i}
43
+ <button
44
+ class="confidence-set group"
45
+ data-testid={`${confidence_set.label}-confidence-set`}
46
+ class:selectable
47
+ onclick={() => {
48
+ onselect?.({ index: i, value: confidence_set.label });
49
+ }}
50
+ >
51
+ <div class="inner-wrap">
52
+ <meter
53
+ aria-labelledby={get_aria_referenceable_id(
54
+ `meter-text-${confidence_set.label}`
55
+ )}
56
+ aria-label={confidence_set.label}
57
+ aria-valuenow={Math.round(confidence_set.confidence * 100)}
58
+ aria-valuemin="0"
59
+ aria-valuemax="100"
60
+ class="bar"
61
+ min="0"
62
+ max="1"
63
+ value={confidence_set.confidence}
64
+ style="width: {confidence_set.confidence *
65
+ 100}%; background: var(--stat-background-fill);
66
+ "
67
+ />
68
+
69
+ <dl class="label">
70
+ <dt
71
+ id={get_aria_referenceable_id(
72
+ `meter-text-${confidence_set.label}`
73
+ )}
74
+ class="text"
75
+ >
76
+ {confidence_set.label}
77
+ </dt>
78
+ <div class="line" />
79
+ <dd class="confidence">
80
+ {Math.round(confidence_set.confidence * 100)}%
81
+ </dd>
82
+ </dl>
83
+ </div>
84
+ </button>
85
+ {/each}
86
+ {/if}
87
+ </div>
88
+
89
+ <style>
90
+ .container {
91
+ padding: var(--block-padding);
92
+ }
93
+ .output-class {
94
+ display: flex;
95
+ justify-content: center;
96
+ align-items: center;
97
+ padding: var(--size-6) var(--size-4);
98
+ color: var(--body-text-color);
99
+ font-weight: var(--weight-bold);
100
+ font-size: var(--text-xxl);
101
+ }
102
+
103
+ .confidence-set {
104
+ display: flex;
105
+ justify-content: space-between;
106
+ align-items: flex-start;
107
+ margin-bottom: var(--size-2);
108
+ color: var(--body-text-color);
109
+ line-height: var(--line-none);
110
+ font-family: var(--font-mono);
111
+ width: 100%;
112
+ }
113
+
114
+ .confidence-set:last-child {
115
+ margin-bottom: 0;
116
+ }
117
+
118
+ .inner-wrap {
119
+ flex: 1 1 0%;
120
+ display: flex;
121
+ flex-direction: column;
122
+ }
123
+
124
+ .bar {
125
+ appearance: none;
126
+ -webkit-appearance: none;
127
+ -moz-appearance: none;
128
+ align-self: flex-start;
129
+ margin-bottom: var(--size-1);
130
+ border-radius: var(--radius-md);
131
+ background: var(--stat-background-fill);
132
+ height: var(--size-1);
133
+ border: none;
134
+ }
135
+
136
+ .bar::-moz-meter-bar {
137
+ border-radius: var(--radius-md);
138
+ background: var(--stat-background-fill);
139
+ }
140
+
141
+ .bar::-webkit-meter-bar {
142
+ border-radius: var(--radius-md);
143
+ background: var(--stat-background-fill);
144
+ border: none;
145
+ }
146
+
147
+ .bar::-webkit-meter-optimum-value,
148
+ .bar::-webkit-meter-suboptimum-value,
149
+ .bar::-webkit-meter-even-less-good-value {
150
+ border-radius: var(--radius-md);
151
+ background: var(--stat-background-fill);
152
+ }
153
+
154
+ .bar::-ms-fill {
155
+ border-radius: var(--radius-md);
156
+ background: var(--stat-background-fill);
157
+ border: none;
158
+ }
159
+
160
+ .label {
161
+ display: flex;
162
+ align-items: baseline;
163
+ }
164
+
165
+ .label > * + * {
166
+ margin-left: var(--size-2);
167
+ }
168
+
169
+ .confidence-set:hover .label {
170
+ color: var(--color-accent);
171
+ }
172
+
173
+ .confidence-set:focus .label {
174
+ color: var(--color-accent);
175
+ }
176
+
177
+ .text {
178
+ line-height: var(--line-md);
179
+ text-align: left;
180
+ }
181
+
182
+ .line {
183
+ flex: 1 1 0%;
184
+ border: 1px dashed var(--border-color-primary);
185
+ padding-right: var(--size-4);
186
+ padding-left: var(--size-4);
187
+ }
188
+
189
+ .confidence {
190
+ margin-left: auto;
191
+ text-align: right;
192
+ }
193
+ </style>
6.4.0/label/types.ts ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type { SelectData, LoadingStatus, CustomButton } from "@gradio/utils";
2
+
3
+ export interface LabelProps {
4
+ value: {
5
+ label?: string;
6
+ confidences?: { label: string; confidence: number }[];
7
+ };
8
+ color: undefined | string;
9
+ _selectable: boolean;
10
+ show_heading: boolean;
11
+ buttons: (string | CustomButton)[] | null;
12
+ }
13
+
14
+ export interface LabelEvents {
15
+ change: never;
16
+ select: SelectData;
17
+ clear_status: LoadingStatus;
18
+ custom_button_click: { id: number };
19
+ }