@gradio/video 0.1.0-beta.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,106 @@
1
+ <svelte:options accessors={true} />
2
+
3
+ <script lang="ts">
4
+ import type { Gradio, ShareData } from "@gradio/utils";
5
+ import type { FileData } from "@gradio/upload";
6
+ import { normalise_file } from "@gradio/upload";
7
+ import { Block } from "@gradio/atoms";
8
+ import StaticVideo from "./VideoPreview.svelte";
9
+
10
+ import { StatusTracker } from "@gradio/statustracker";
11
+ import type { LoadingStatus } from "@gradio/statustracker";
12
+
13
+ export let elem_id = "";
14
+ export let elem_classes: string[] = [];
15
+ export let visible = true;
16
+ export let value: { video: FileData; subtitles: FileData | null } | null =
17
+ null;
18
+ let old_value: { video: FileData; subtitles: FileData | null } | null = null;
19
+
20
+ export let label: string;
21
+ export let source: "upload" | "webcam";
22
+ export let root: string;
23
+ export let root_url: null | string;
24
+ export let show_label: boolean;
25
+ export let loading_status: LoadingStatus;
26
+ export let height: number | undefined;
27
+ export let width: number | undefined;
28
+
29
+ export let container = false;
30
+ export let scale: number | null = null;
31
+ export let min_width: number | undefined = undefined;
32
+ export let autoplay = false;
33
+ export let show_share_button = true;
34
+ export let gradio: Gradio<{
35
+ change: never;
36
+ clear: never;
37
+ play: never;
38
+ pause: never;
39
+ upload: never;
40
+ stop: never;
41
+ end: never;
42
+ start_recording: never;
43
+ stop_recording: never;
44
+ share: ShareData;
45
+ error: string;
46
+ }>;
47
+
48
+ let _video: FileData | null = null;
49
+ let _subtitle: FileData | null = null;
50
+
51
+ $: {
52
+ if (value != null) {
53
+ _video = normalise_file(value.video, root, root_url);
54
+ _subtitle = normalise_file(value.subtitles, root, root_url);
55
+ } else {
56
+ _video = null;
57
+ _subtitle = null;
58
+ }
59
+ }
60
+
61
+ let dragging = false;
62
+
63
+ $: {
64
+ if (JSON.stringify(value) !== JSON.stringify(old_value)) {
65
+ old_value = value;
66
+ gradio.dispatch("change");
67
+ }
68
+ }
69
+ </script>
70
+
71
+ <Block
72
+ {visible}
73
+ variant={value === null && source === "upload" ? "dashed" : "solid"}
74
+ border_mode={dragging ? "focus" : "base"}
75
+ padding={false}
76
+ {elem_id}
77
+ {elem_classes}
78
+ {height}
79
+ {width}
80
+ {container}
81
+ {scale}
82
+ {min_width}
83
+ allow_overflow={false}
84
+ >
85
+ <StatusTracker
86
+ autoscroll={gradio.autoscroll}
87
+ i18n={gradio.i18n}
88
+ {...loading_status}
89
+ />
90
+
91
+ <StaticVideo
92
+ value={_video}
93
+ subtitle={_subtitle}
94
+ {label}
95
+ {show_label}
96
+ {autoplay}
97
+ {show_share_button}
98
+ on:play={() => gradio.dispatch("play")}
99
+ on:pause={() => gradio.dispatch("pause")}
100
+ on:stop={() => gradio.dispatch("stop")}
101
+ on:end={() => gradio.dispatch("end")}
102
+ on:share={({ detail }) => gradio.dispatch("share", detail)}
103
+ on:error={({ detail }) => gradio.dispatch("error", detail)}
104
+ i18n={gradio.i18n}
105
+ />
106
+ </Block>
@@ -0,0 +1,98 @@
1
+ <script lang="ts">
2
+ import { createEventDispatcher, afterUpdate, tick } from "svelte";
3
+ import { BlockLabel, Empty, IconButton, ShareButton } from "@gradio/atoms";
4
+ import type { FileData } from "@gradio/upload";
5
+ import { Video, Download } from "@gradio/icons";
6
+ import { uploadToHuggingFace } from "@gradio/utils";
7
+
8
+ import { Player } from "../shared";
9
+ import type { I18nFormatter } from "js/app/src/gradio_helper";
10
+
11
+ export let value: FileData | null = null;
12
+ export let subtitle: FileData | null = null;
13
+ export let label: string | undefined = undefined;
14
+ export let show_label = true;
15
+ export let autoplay: boolean;
16
+ export let show_share_button = true;
17
+ export let i18n: I18nFormatter;
18
+
19
+ let old_value: FileData | null = null;
20
+ let old_subtitle: FileData | null = null;
21
+
22
+ const dispatch = createEventDispatcher<{
23
+ change: FileData;
24
+ play: undefined;
25
+ pause: undefined;
26
+ end: undefined;
27
+ stop: undefined;
28
+ }>();
29
+
30
+ $: value && dispatch("change", value);
31
+
32
+ afterUpdate(async () => {
33
+ // needed to bust subtitle caching issues on Chrome
34
+ if (
35
+ value !== old_value &&
36
+ subtitle !== old_subtitle &&
37
+ old_subtitle !== null
38
+ ) {
39
+ old_value = value;
40
+ value = null;
41
+ await tick();
42
+ value = old_value;
43
+ }
44
+ old_value = value;
45
+ old_subtitle = subtitle;
46
+ });
47
+ </script>
48
+
49
+ <BlockLabel {show_label} Icon={Video} label={label || "Video"} />
50
+ {#if value === null}
51
+ <Empty unpadded_box={true} size="large"><Video /></Empty>
52
+ {:else}
53
+ {#key value.data}
54
+ <Player
55
+ src={value.data}
56
+ subtitle={subtitle?.data}
57
+ {autoplay}
58
+ on:play
59
+ on:pause
60
+ on:stop
61
+ on:end
62
+ mirror={false}
63
+ {label}
64
+ />
65
+ {/key}
66
+ <div class="icon-buttons" data-testid="download-div">
67
+ <a
68
+ href={value.data}
69
+ target={window.__is_colab__ ? "_blank" : null}
70
+ download={value.orig_name || value.name}
71
+ >
72
+ <IconButton Icon={Download} label="Download" />
73
+ </a>
74
+ {#if show_share_button}
75
+ <ShareButton
76
+ {i18n}
77
+ on:error
78
+ on:share
79
+ {value}
80
+ formatter={async (value) => {
81
+ if (!value) return "";
82
+ let url = await uploadToHuggingFace(value.data, "url");
83
+ return url;
84
+ }}
85
+ />
86
+ {/if}
87
+ </div>
88
+ {/if}
89
+
90
+ <style>
91
+ .icon-buttons {
92
+ display: flex;
93
+ position: absolute;
94
+ top: 6px;
95
+ right: 6px;
96
+ gap: var(--size-1);
97
+ }
98
+ </style>
@@ -0,0 +1 @@
1
+ export { default } from "./StaticVideo.svelte";