2022-02-07 22:34:53 +08:00
|
|
|
<script lang="ts">
|
2023-02-02 20:16:38 +08:00
|
|
|
import { createEventDispatcher } from "svelte";
|
2022-03-08 21:35:42 +08:00
|
|
|
import type { FileData } from "@gradio/upload";
|
2022-04-08 01:18:41 +08:00
|
|
|
import { normalise_file } from "@gradio/upload";
|
2022-04-26 22:48:39 +08:00
|
|
|
import { Block } from "@gradio/atoms";
|
2022-04-14 22:12:30 +08:00
|
|
|
import { Video, StaticVideo } from "@gradio/video";
|
2023-01-18 04:47:40 +08:00
|
|
|
import UploadText from "../UploadText.svelte";
|
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
|
|
|
import { _ } from "svelte-i18n";
|
2022-02-07 22:34:53 +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;
|
2023-04-12 07:06:48 +08:00
|
|
|
export let value: [FileData, FileData | null] | null = null;
|
|
|
|
let old_value: [FileData, FileData | null] | null = null;
|
2023-02-02 20:16:38 +08:00
|
|
|
|
2022-04-08 01:18:41 +08:00
|
|
|
export let label: string;
|
2022-02-07 22:34:53 +08:00
|
|
|
export let source: string;
|
2022-04-12 04:18:42 +08:00
|
|
|
export let root: string;
|
2022-11-04 03:35:56 +08:00
|
|
|
export let root_url: null | string;
|
2022-04-27 18:47:15 +08:00
|
|
|
export let show_label: boolean;
|
2022-05-06 03:05:05 +08:00
|
|
|
export let loading_status: LoadingStatus;
|
2023-06-08 09:35:31 +08:00
|
|
|
export let height: number | undefined;
|
|
|
|
export let width: number | undefined;
|
2022-07-06 00:30:02 +08:00
|
|
|
export let mirror_webcam: boolean;
|
2022-12-27 02:56:17 +08:00
|
|
|
export let include_audio: boolean;
|
2023-06-08 09:35:31 +08:00
|
|
|
export let container: boolean = false;
|
|
|
|
export let scale: number = 1;
|
|
|
|
export let min_width: number | undefined = undefined;
|
2022-03-12 00:00:48 +08:00
|
|
|
export let mode: "static" | "dynamic";
|
2023-06-09 07:27:58 +08:00
|
|
|
export let autoplay: boolean = false;
|
|
|
|
|
2023-04-12 07:06:48 +08:00
|
|
|
let _video: FileData | null = null;
|
|
|
|
let _subtitle: FileData | null = null;
|
|
|
|
|
|
|
|
$: {
|
|
|
|
if (value != null) {
|
|
|
|
_video = normalise_file(value[0], root, root_url);
|
|
|
|
_subtitle = normalise_file(value[1], root, root_url);
|
|
|
|
} else {
|
|
|
|
_video = null;
|
|
|
|
_subtitle = null;
|
|
|
|
}
|
|
|
|
}
|
2022-04-26 22:48:39 +08:00
|
|
|
|
|
|
|
let dragging = false;
|
2023-02-02 20:16:38 +08:00
|
|
|
|
|
|
|
const dispatch = createEventDispatcher<{
|
|
|
|
change: undefined;
|
|
|
|
}>();
|
|
|
|
|
2023-04-12 07:06:48 +08:00
|
|
|
function handle_change({ detail }: CustomEvent<FileData | null>) {
|
|
|
|
if (detail != null) {
|
|
|
|
value = [detail, null] as [FileData, FileData | null];
|
|
|
|
} else {
|
|
|
|
value = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch("change");
|
|
|
|
}
|
|
|
|
|
2023-02-02 20:16:38 +08:00
|
|
|
$: {
|
2023-04-12 07:06:48 +08:00
|
|
|
if (JSON.stringify(value) !== JSON.stringify(old_value)) {
|
2023-02-02 20:16:38 +08:00
|
|
|
old_value = value;
|
|
|
|
dispatch("change");
|
|
|
|
}
|
|
|
|
}
|
2022-02-01 21:45:55 +08:00
|
|
|
</script>
|
|
|
|
|
2022-04-26 22:48:39 +08:00
|
|
|
<Block
|
2022-06-17 07:49:54 +08:00
|
|
|
{visible}
|
2022-04-26 22:48:39 +08:00
|
|
|
variant={mode === "dynamic" && value === null && source === "upload"
|
|
|
|
? "dashed"
|
|
|
|
: "solid"}
|
2023-03-07 04:52:31 +08:00
|
|
|
border_mode={dragging ? "focus" : "base"}
|
2022-04-26 22:48:39 +08:00
|
|
|
padding={false}
|
2022-05-12 12:40:41 +08:00
|
|
|
{elem_id}
|
2023-03-16 05:01:53 +08:00
|
|
|
{elem_classes}
|
2023-06-08 09:35:31 +08:00
|
|
|
{height}
|
|
|
|
{width}
|
|
|
|
{container}
|
|
|
|
{scale}
|
|
|
|
{min_width}
|
2023-01-21 05:24:24 +08:00
|
|
|
allow_overflow={false}
|
2022-04-26 22:48:39 +08:00
|
|
|
>
|
2022-05-06 03:05:05 +08:00
|
|
|
<StatusTracker {...loading_status} />
|
2022-04-26 22:48:39 +08:00
|
|
|
|
|
|
|
{#if mode === "static"}
|
2023-04-12 07:06:48 +08:00
|
|
|
<StaticVideo
|
|
|
|
value={_video}
|
|
|
|
subtitle={_subtitle}
|
|
|
|
{label}
|
|
|
|
{show_label}
|
2023-06-09 07:27:58 +08:00
|
|
|
{autoplay}
|
2023-04-12 07:06:48 +08:00
|
|
|
on:play
|
|
|
|
on:pause
|
2023-06-08 11:54:02 +08:00
|
|
|
on:stop
|
2023-04-12 07:06:48 +08:00
|
|
|
/>
|
2022-04-26 22:48:39 +08:00
|
|
|
{:else}
|
|
|
|
<Video
|
2023-04-12 07:06:48 +08:00
|
|
|
value={_video}
|
|
|
|
subtitle={_subtitle}
|
|
|
|
on:change={handle_change}
|
2022-04-26 22:48:39 +08:00
|
|
|
on:drag={({ detail }) => (dragging = detail)}
|
2022-09-29 22:33:22 +08:00
|
|
|
on:error={({ detail }) => {
|
|
|
|
loading_status = loading_status || {};
|
|
|
|
loading_status.status = "error";
|
|
|
|
loading_status.message = detail;
|
|
|
|
}}
|
2022-04-26 22:48:39 +08:00
|
|
|
{label}
|
2022-04-27 18:47:15 +08:00
|
|
|
{show_label}
|
2022-04-26 22:48:39 +08:00
|
|
|
{source}
|
2022-07-06 00:30:02 +08:00
|
|
|
{mirror_webcam}
|
2022-12-27 02:56:17 +08:00
|
|
|
{include_audio}
|
2023-06-09 07:27:58 +08:00
|
|
|
{autoplay}
|
2022-04-26 22:48:39 +08:00
|
|
|
on:clear
|
|
|
|
on:play
|
|
|
|
on:pause
|
2022-10-26 08:58:12 +08:00
|
|
|
on:upload
|
2023-06-08 11:54:02 +08:00
|
|
|
on:stop
|
|
|
|
on:end
|
|
|
|
on:start_recording
|
|
|
|
on:stop_recording
|
2023-01-18 04:47:40 +08:00
|
|
|
>
|
|
|
|
<UploadText type="video" />
|
|
|
|
</Video>
|
2022-04-26 22:48:39 +08:00
|
|
|
{/if}
|
|
|
|
</Block>
|