gradio/js/app/src/components/Video/Video.svelte

131 lines
2.9 KiB
Svelte
Raw Normal View History

<script lang="ts">
import { createEventDispatcher } from "svelte";
2022-03-08 21:35:42 +08:00
import type { FileData } from "@gradio/upload";
import { normalise_file } from "@gradio/upload";
import { Block } from "@gradio/atoms";
import { Video, StaticVideo } from "@gradio/video";
import UploadText from "../UploadText.svelte";
import StatusTracker from "../StatusTracker/StatusTracker.svelte";
import type { LoadingStatus } from "../StatusTracker/types";
2022-03-08 21:35:42 +08:00
import { _ } from "svelte-i18n";
export let elem_id: string = "";
export let elem_classes: Array<string> = [];
export let visible: boolean = true;
export let value: [FileData, FileData | null] | null = null;
let old_value: [FileData, FileData | null] | null = null;
export let label: string;
export let source: string;
export let root: string;
export let root_url: null | string;
export let show_label: boolean;
export let loading_status: LoadingStatus;
export let height: number | undefined;
export let width: number | undefined;
export let mirror_webcam: boolean;
export let include_audio: boolean;
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";
export let autoplay: boolean = false;
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;
}
}
let dragging = false;
const dispatch = createEventDispatcher<{
change: undefined;
}>();
function handle_change({ detail }: CustomEvent<FileData | null>) {
if (detail != null) {
value = [detail, null] as [FileData, FileData | null];
} else {
value = null;
}
dispatch("change");
}
$: {
if (JSON.stringify(value) !== JSON.stringify(old_value)) {
old_value = value;
dispatch("change");
}
}
</script>
<Block
{visible}
variant={mode === "dynamic" && value === null && source === "upload"
? "dashed"
: "solid"}
Python backend to theming (#2931) * add theme + theme atoms * audio * buttons * chatbot * forms * start file * complete file * fixup workbench * gallery * highlighted text * label * json * upload * 3d model * atoms * chart * md + html * image * plot + build * table * tabs * tooltip * upload * tweaks * tweaks + more tooling * tweaks to padding/ lineheight * app components _ start api docs * format, more api docs * finish api docs * interpretation * todos * tweaks + cleanup * tweaks + cleanup * revert range tweaks * fix notebooks * fix test * remove tw * cleanup + login * fix gitignore * fix types * run css script * fix progress + tweaks * update demos * add css build to static check workflow * tweak ci * fix tests * tweak markdown * tweak chatbot + file * fix tabs * tweak tabs * cleanup * fix api docs * fix example gallery * add gradient to toast * fix min height for interfaces * revert tab changes * update notebooks * changes * changes * change * changes * changes * changes * changes * changes * changes * changes * changes * change * changes * changes * changes * changes * changes * changes * changes * fix * changes * changes * changes * changes * changes * changes * undo radius * undo radius * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * changes * change * undo * Add absolute imports * mock theme in tests * clean * changes * changes --------- Co-authored-by: pngwn <hello@pngwn.io> Co-authored-by: freddyaboulton <alfonsoboulton@gmail.com> Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
2023-03-07 04:52:31 +08:00
border_mode={dragging ? "focus" : "base"}
padding={false}
{elem_id}
{elem_classes}
{height}
{width}
{container}
{scale}
{min_width}
allow_overflow={false}
>
<StatusTracker {...loading_status} />
{#if mode === "static"}
<StaticVideo
value={_video}
subtitle={_subtitle}
{label}
{show_label}
{autoplay}
on:play
on:pause
2023-06-08 11:54:02 +08:00
on:stop
/>
{:else}
<Video
value={_video}
subtitle={_subtitle}
on:change={handle_change}
on:drag={({ detail }) => (dragging = detail)}
on:error={({ detail }) => {
loading_status = loading_status || {};
loading_status.status = "error";
loading_status.message = detail;
}}
{label}
{show_label}
{source}
{mirror_webcam}
{include_audio}
{autoplay}
on:clear
on:play
on:pause
on:upload
2023-06-08 11:54:02 +08:00
on:stop
on:end
on:start_recording
on:stop_recording
>
<UploadText type="video" />
</Video>
{/if}
</Block>