2022-03-08 21:35:42 +08:00
|
|
|
<script lang="ts">
|
2022-03-17 00:34:30 +08:00
|
|
|
import { createEventDispatcher } from "svelte";
|
2022-03-08 21:35:42 +08:00
|
|
|
import { Label } from "@gradio/label";
|
2022-05-13 01:47:40 +08:00
|
|
|
import { LineChart as LabelIcon } from "@gradio/icons";
|
2023-01-18 04:47:40 +08:00
|
|
|
import { Block, BlockLabel, Empty } from "@gradio/atoms";
|
2022-04-26 22:48:39 +08:00
|
|
|
import StatusTracker from "../StatusTracker/StatusTracker.svelte";
|
2022-05-06 03:05:05 +08:00
|
|
|
import type { LoadingStatus } from "../StatusTracker/types";
|
2022-03-08 21:35:42 +08:00
|
|
|
|
2022-05-12 12:40:41 +08:00
|
|
|
export let elem_id: string = "";
|
2023-03-16 05:01:53 +08:00
|
|
|
export let elem_classes: Array<string> = [];
|
2022-06-17 07:49:54 +08:00
|
|
|
export let visible: boolean = true;
|
2022-12-02 03:30:11 +08:00
|
|
|
export let color: undefined | string = undefined;
|
2022-03-08 21:35:42 +08:00
|
|
|
export let value: {
|
2023-06-02 13:31:09 +08:00
|
|
|
label?: string;
|
2022-03-08 21:35:42 +08:00
|
|
|
confidences?: Array<{ label: string; confidence: number }>;
|
2023-06-02 13:31:09 +08:00
|
|
|
} = {};
|
2022-05-13 08:23:45 +08:00
|
|
|
export let label: string = "Label";
|
2023-06-08 09:35:31 +08:00
|
|
|
export let container: boolean = false;
|
2023-06-22 03:34:12 +08:00
|
|
|
export let scale: number | null = null;
|
2023-06-08 09:35:31 +08:00
|
|
|
export let min_width: number | undefined = undefined;
|
2022-05-06 03:05:05 +08:00
|
|
|
export let loading_status: LoadingStatus;
|
2023-07-06 17:55:45 +08:00
|
|
|
export let show_label: boolean = true;
|
2023-03-14 08:12:41 +08:00
|
|
|
export let selectable: boolean = false;
|
2022-03-17 00:34:30 +08:00
|
|
|
|
|
|
|
const dispatch = createEventDispatcher<{ change: undefined }>();
|
|
|
|
|
2023-06-02 13:31:09 +08:00
|
|
|
$: ({ confidences, label: _label } = value);
|
|
|
|
$: _label, confidences, dispatch("change");
|
2022-03-08 21:35:42 +08:00
|
|
|
</script>
|
|
|
|
|
2022-06-02 01:02:18 +08:00
|
|
|
<Block
|
2022-07-01 13:27:47 +08:00
|
|
|
test_id="label"
|
2022-06-17 07:49:54 +08:00
|
|
|
{visible}
|
2022-06-02 01:02:18 +08:00
|
|
|
{elem_id}
|
2023-03-16 05:01:53 +08:00
|
|
|
{elem_classes}
|
2023-06-08 09:35:31 +08:00
|
|
|
{container}
|
|
|
|
{scale}
|
|
|
|
{min_width}
|
2023-06-08 20:24:13 +08:00
|
|
|
padding={false}
|
2022-06-02 01:02:18 +08:00
|
|
|
>
|
2022-05-06 03:05:05 +08:00
|
|
|
<StatusTracker {...loading_status} />
|
2022-06-02 01:02:18 +08:00
|
|
|
{#if show_label}
|
2023-06-08 09:35:31 +08:00
|
|
|
<BlockLabel Icon={LabelIcon} {label} disable={container === false} />
|
2022-06-02 01:02:18 +08:00
|
|
|
{/if}
|
2023-06-08 06:28:15 +08:00
|
|
|
{#if _label !== undefined && _label !== null}
|
2023-06-29 23:42:26 +08:00
|
|
|
<Label on:select {selectable} {value} {color} />
|
2022-05-13 01:47:40 +08:00
|
|
|
{:else}
|
2023-06-08 20:24:13 +08:00
|
|
|
<Empty unpadded_box={true}><LabelIcon /></Empty>
|
2022-04-26 22:48:39 +08:00
|
|
|
{/if}
|
|
|
|
</Block>
|