2023-10-31 12:46:02 +08:00
|
|
|
<script context="module" lang="ts">
|
|
|
|
export { default as BaseGallery } from "./shared/Gallery.svelte";
|
|
|
|
</script>
|
|
|
|
|
2022-05-04 05:49:51 +08:00
|
|
|
<script lang="ts">
|
2023-08-24 04:48:10 +08:00
|
|
|
import type { Gradio, ShareData, SelectData } from "@gradio/utils";
|
2024-01-26 07:51:59 +08:00
|
|
|
import { Block, UploadText } from "@gradio/atoms";
|
2023-10-31 12:46:02 +08:00
|
|
|
import Gallery from "./shared/Gallery.svelte";
|
2023-08-16 02:21:41 +08:00
|
|
|
import type { LoadingStatus } from "@gradio/statustracker";
|
2022-05-06 03:05:05 +08:00
|
|
|
import { StatusTracker } from "@gradio/statustracker";
|
2023-10-31 12:46:02 +08:00
|
|
|
import type { FileData } from "@gradio/client";
|
2023-11-03 20:52:32 +08:00
|
|
|
import { createEventDispatcher } from "svelte";
|
2024-01-26 07:51:59 +08:00
|
|
|
import { BaseFileUpload } from "@gradio/file";
|
2022-05-04 05:49:51 +08:00
|
|
|
|
2022-05-06 03:05:05 +08:00
|
|
|
export let loading_status: LoadingStatus;
|
2022-05-04 05:49:51 +08:00
|
|
|
export let show_label: boolean;
|
|
|
|
export let label: string;
|
2022-10-07 13:08:30 +08:00
|
|
|
export let root: string;
|
2023-07-25 22:02:44 +08:00
|
|
|
export let elem_id = "";
|
|
|
|
export let elem_classes: string[] = [];
|
|
|
|
export let visible = true;
|
2024-01-26 07:51:59 +08:00
|
|
|
export let value: { image: FileData; caption: string | null }[] | null = null;
|
2023-07-25 22:02:44 +08:00
|
|
|
export let container = true;
|
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;
|
2023-10-03 11:11:09 +08:00
|
|
|
export let columns: number | number[] | undefined = [2];
|
|
|
|
export let rows: number | number[] | undefined = undefined;
|
2023-06-08 09:35:31 +08:00
|
|
|
export let height: number | "auto" = "auto";
|
|
|
|
export let preview: boolean;
|
2023-07-25 22:02:44 +08:00
|
|
|
export let allow_preview = true;
|
2023-10-06 02:35:42 +08:00
|
|
|
export let selected_index: number | null = null;
|
2023-06-08 09:35:31 +08:00
|
|
|
export let object_fit: "contain" | "cover" | "fill" | "none" | "scale-down" =
|
|
|
|
"cover";
|
2023-07-25 22:02:44 +08:00
|
|
|
export let show_share_button = false;
|
2024-01-26 07:51:59 +08:00
|
|
|
export let interactive: boolean;
|
2023-08-01 01:31:49 +08:00
|
|
|
export let show_download_button = false;
|
2023-08-24 04:48:10 +08:00
|
|
|
export let gradio: Gradio<{
|
2023-10-05 03:25:03 +08:00
|
|
|
change: typeof value;
|
2024-01-26 07:51:59 +08:00
|
|
|
upload: typeof value;
|
2023-08-24 04:48:10 +08:00
|
|
|
select: SelectData;
|
|
|
|
share: ShareData;
|
|
|
|
error: string;
|
2023-11-03 20:52:32 +08:00
|
|
|
prop_change: Record<string, any>;
|
2023-08-24 04:48:10 +08:00
|
|
|
}>;
|
2023-11-03 20:52:32 +08:00
|
|
|
|
|
|
|
const dispatch = createEventDispatcher();
|
|
|
|
|
2024-01-26 07:51:59 +08:00
|
|
|
$: no_value = Array.isArray(value) ? value.length === 0 : !value;
|
2023-11-03 20:52:32 +08:00
|
|
|
$: selected_index, dispatch("prop_change", { selected_index });
|
2022-05-04 05:49:51 +08:00
|
|
|
</script>
|
|
|
|
|
2022-06-02 01:02:18 +08:00
|
|
|
<Block
|
2022-06-17 07:49:54 +08:00
|
|
|
{visible}
|
2022-06-02 01:02:18 +08:00
|
|
|
variant="solid"
|
|
|
|
padding={false}
|
|
|
|
{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-07-06 08:50:17 +08:00
|
|
|
allow_overflow={false}
|
2023-06-08 09:35:31 +08:00
|
|
|
height={typeof height === "number" ? height : undefined}
|
2022-06-02 01:02:18 +08:00
|
|
|
>
|
2023-10-31 12:46:02 +08:00
|
|
|
<StatusTracker
|
|
|
|
autoscroll={gradio.autoscroll}
|
|
|
|
i18n={gradio.i18n}
|
|
|
|
{...loading_status}
|
|
|
|
/>
|
2024-01-26 07:51:59 +08:00
|
|
|
{#if interactive && no_value}
|
|
|
|
<BaseFileUpload
|
|
|
|
value={null}
|
|
|
|
{root}
|
|
|
|
{label}
|
|
|
|
file_count={"multiple"}
|
|
|
|
file_types={["image"]}
|
|
|
|
i18n={gradio.i18n}
|
|
|
|
on:upload={(e) => {
|
|
|
|
const files = Array.isArray(e.detail) ? e.detail : [e.detail];
|
|
|
|
value = files.map((x) => ({ image: x, caption: null }));
|
|
|
|
gradio.dispatch("upload", value);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<UploadText i18n={gradio.i18n} type="gallery" />
|
|
|
|
</BaseFileUpload>
|
|
|
|
{:else}
|
|
|
|
<Gallery
|
|
|
|
on:change={() => gradio.dispatch("change", value)}
|
|
|
|
on:select={(e) => gradio.dispatch("select", e.detail)}
|
|
|
|
on:share={(e) => gradio.dispatch("share", e.detail)}
|
|
|
|
on:error={(e) => gradio.dispatch("error", e.detail)}
|
|
|
|
{label}
|
|
|
|
{show_label}
|
|
|
|
{columns}
|
|
|
|
{rows}
|
|
|
|
{height}
|
|
|
|
{preview}
|
|
|
|
{object_fit}
|
|
|
|
{interactive}
|
|
|
|
{allow_preview}
|
|
|
|
bind:selected_index
|
|
|
|
bind:value
|
|
|
|
{show_share_button}
|
|
|
|
{show_download_button}
|
|
|
|
i18n={gradio.i18n}
|
|
|
|
/>
|
|
|
|
{/if}
|
2022-05-04 05:49:51 +08:00
|
|
|
</Block>
|