Upload folder using huggingface_hub
Browse files- 6.2.0/label/Index.svelte +63 -0
- 6.2.0/label/package.json +36 -0
- 6.2.0/label/shared/Label.svelte +188 -0
- 6.2.0/label/types.ts +17 -0
6.2.0/label/Index.svelte
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 } from "@gradio/atoms";
|
| 11 |
+
import { StatusTracker } from "@gradio/statustracker";
|
| 12 |
+
|
| 13 |
+
const props = $props();
|
| 14 |
+
const gradio = new Gradio<LabelEvents, LabelProps>(props);
|
| 15 |
+
|
| 16 |
+
let old_value = $state(gradio.props.value);
|
| 17 |
+
let _label = $derived(gradio.props.value.label);
|
| 18 |
+
|
| 19 |
+
$effect(() => {
|
| 20 |
+
if (old_value != gradio.props.value) {
|
| 21 |
+
old_value = gradio.props.value;
|
| 22 |
+
gradio.dispatch("change");
|
| 23 |
+
}
|
| 24 |
+
});
|
| 25 |
+
</script>
|
| 26 |
+
|
| 27 |
+
<Block
|
| 28 |
+
test_id="label"
|
| 29 |
+
visible={gradio.shared.visible}
|
| 30 |
+
elem_id={gradio.shared.elem_id}
|
| 31 |
+
elem_classes={gradio.shared.elem_classes}
|
| 32 |
+
container={gradio.shared.container}
|
| 33 |
+
scale={gradio.shared.scale}
|
| 34 |
+
min_width={gradio.shared.min_width}
|
| 35 |
+
padding={false}
|
| 36 |
+
>
|
| 37 |
+
<StatusTracker
|
| 38 |
+
autoscroll={gradio.shared.autoscroll}
|
| 39 |
+
i18n={gradio.i18n}
|
| 40 |
+
{...gradio.shared.loading_status}
|
| 41 |
+
on_clear_status={() =>
|
| 42 |
+
gradio.dispatch("clear_status", gradio.shared.loading_status)}
|
| 43 |
+
/>
|
| 44 |
+
{#if gradio.shared.show_label}
|
| 45 |
+
<BlockLabel
|
| 46 |
+
Icon={LabelIcon}
|
| 47 |
+
label={gradio.shared.label || gradio.i18n("label.label")}
|
| 48 |
+
disable={gradio.shared.container === false}
|
| 49 |
+
float={gradio.props.show_heading === true}
|
| 50 |
+
/>
|
| 51 |
+
{/if}
|
| 52 |
+
{#if _label !== undefined && _label !== null}
|
| 53 |
+
<Label
|
| 54 |
+
on:select={({ detail }) => gradio.dispatch("select", detail)}
|
| 55 |
+
selectable={gradio.props._selectable}
|
| 56 |
+
value={gradio.props.value}
|
| 57 |
+
color={gradio.props.color}
|
| 58 |
+
show_heading={gradio.props.show_heading}
|
| 59 |
+
/>
|
| 60 |
+
{:else}
|
| 61 |
+
<Empty unpadded_box={true}><LabelIcon /></Empty>
|
| 62 |
+
{/if}
|
| 63 |
+
</Block>
|
6.2.0/label/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "@gradio/label",
|
| 3 |
+
"version": "0.5.22",
|
| 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.2.0/label/shared/Label.svelte
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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">
|
| 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>
|
6.2.0/label/types.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { SelectData, LoadingStatus } 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 |
+
}
|
| 12 |
+
|
| 13 |
+
export interface LabelEvents {
|
| 14 |
+
change: never;
|
| 15 |
+
select: SelectData;
|
| 16 |
+
clear_status: LoadingStatus;
|
| 17 |
+
}
|