gradio-pr-bot commited on
Commit
8b67adc
·
verified ·
1 Parent(s): 4594346

Upload folder using huggingface_hub

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