-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
Index.svelte
172 lines (161 loc) 路 4.29 KB
/
Index.svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<svelte:options accessors={true} />
<script lang="ts">
import type { Gradio, ShareData } from "@gradio/utils";
import type { FileData } from "@gradio/upload";
import { normalise_file } from "@gradio/upload";
import { Block, UploadText } from "@gradio/atoms";
import StaticVideo from "./shared/VideoPreview.svelte";
import Video from "./shared/InteractiveVideo.svelte";
import { StatusTracker } from "@gradio/statustracker";
import type { LoadingStatus } from "@gradio/statustracker";
export let elem_id = "";
export let elem_classes: string[] = [];
export let visible = true;
export let value: { video: FileData; subtitles: FileData | null } | null =
null;
let old_value: { video: FileData; subtitles: FileData | null } | null = null;
export let label: string;
export let source: "upload" | "webcam";
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 container = false;
export let scale: number | null = null;
export let min_width: number | undefined = undefined;
export let autoplay = false;
export let show_share_button = true;
export let gradio: Gradio<{
change: never;
clear: never;
play: never;
pause: never;
upload: never;
stop: never;
end: never;
start_recording: never;
stop_recording: never;
share: ShareData;
error: string;
}>;
export let mode: "static" | "interactive";
export let mirror_webcam: boolean;
export let include_audio: boolean;
let _video: FileData | null = null;
let _subtitle: FileData | null = null;
$: {
if (value != null) {
_video = normalise_file(value.video, root, root_url);
_subtitle = normalise_file(value.subtitles, root, root_url);
} else {
_video = null;
_subtitle = null;
}
}
let dragging = false;
$: {
if (JSON.stringify(value) !== JSON.stringify(old_value)) {
old_value = value;
gradio.dispatch("change");
}
}
function handle_change({ detail }: CustomEvent<FileData | null>): void {
if (detail != null) {
value = { video: detail, subtitles: null } as {
video: FileData;
subtitles: FileData | null;
} | null;
} else {
value = null;
}
}
</script>
{#if mode === "static"}
<Block
{visible}
variant={value === null && source === "upload" ? "dashed" : "solid"}
border_mode={dragging ? "focus" : "base"}
padding={false}
{elem_id}
{elem_classes}
{height}
{width}
{container}
{scale}
{min_width}
allow_overflow={false}
>
<StatusTracker
autoscroll={gradio.autoscroll}
i18n={gradio.i18n}
{...loading_status}
/>
<StaticVideo
value={_video}
subtitle={_subtitle}
{label}
{show_label}
{autoplay}
{show_share_button}
on:play={() => gradio.dispatch("play")}
on:pause={() => gradio.dispatch("pause")}
on:stop={() => gradio.dispatch("stop")}
on:end={() => gradio.dispatch("end")}
on:share={({ detail }) => gradio.dispatch("share", detail)}
on:error={({ detail }) => gradio.dispatch("error", detail)}
i18n={gradio.i18n}
/>
</Block>
{:else}
<Block
{visible}
variant={value === null && source === "upload" ? "dashed" : "solid"}
border_mode={dragging ? "focus" : "base"}
padding={false}
{elem_id}
{elem_classes}
{height}
{width}
{container}
{scale}
{min_width}
allow_overflow={false}
>
<StatusTracker
autoscroll={gradio.autoscroll}
i18n={gradio.i18n}
{...loading_status}
/>
<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}
{root}
on:clear={() => gradio.dispatch("clear")}
on:play={() => gradio.dispatch("play")}
on:pause={() => gradio.dispatch("pause")}
on:upload={() => gradio.dispatch("upload")}
on:stop={() => gradio.dispatch("stop")}
on:end={() => gradio.dispatch("end")}
on:start_recording={() => gradio.dispatch("start_recording")}
on:stop_recording={() => gradio.dispatch("stop_recording")}
i18n={gradio.i18n}
>
<UploadText i18n={gradio.i18n} type="video" />
</Video>
</Block>
{/if}