gradio-pr-bot commited on
Commit
a95ac61
·
verified ·
1 Parent(s): 7a6e3d3

Upload folder using huggingface_hub

Browse files
5.49.1/file/Example.svelte ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import type { FileData } from "@gradio/client";
3
+
4
+ export let value: FileData | null;
5
+ export let type: "gallery" | "table";
6
+ export let selected = false;
7
+ </script>
8
+
9
+ <div
10
+ class:table={type === "table"}
11
+ class:gallery={type === "gallery"}
12
+ class:selected
13
+ >
14
+ {value ? (Array.isArray(value) ? value.join(", ") : value) : ""}
15
+ </div>
16
+
17
+ <style>
18
+ div {
19
+ overflow: hidden;
20
+ text-overflow: ellipsis;
21
+ white-space: nowrap;
22
+ }
23
+ .gallery {
24
+ display: flex;
25
+ align-items: center;
26
+ cursor: pointer;
27
+ padding: var(--size-1) var(--size-2);
28
+ text-align: left;
29
+ }
30
+ </style>
5.49.1/file/Index.svelte ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <svelte:options accessors={true} />
2
+
3
+ <script context="module" lang="ts">
4
+ export { default as FilePreview } from "./shared/FilePreview.svelte";
5
+ export { default as BaseFileUpload } from "./shared/FileUpload.svelte";
6
+ export { default as BaseFile } from "./shared/File.svelte";
7
+ export { default as BaseExample } from "./Example.svelte";
8
+ </script>
9
+
10
+ <script lang="ts">
11
+ import type { Gradio, SelectData } from "@gradio/utils";
12
+ import File from "./shared/File.svelte";
13
+ import FileUpload from "./shared/FileUpload.svelte";
14
+ import type { FileData } from "@gradio/client";
15
+ import { Block, UploadText } from "@gradio/atoms";
16
+
17
+ import { StatusTracker } from "@gradio/statustracker";
18
+ import type { LoadingStatus } from "@gradio/statustracker";
19
+
20
+ export let elem_id = "";
21
+ export let elem_classes: string[] = [];
22
+ export let visible: boolean | "hidden" = true;
23
+ export let value: null | FileData | FileData[];
24
+
25
+ export let interactive: boolean;
26
+ export let root: string;
27
+ export let label: string;
28
+ export let show_label: boolean;
29
+ export let height: number | undefined = undefined;
30
+
31
+ export let _selectable = false;
32
+ export let loading_status: LoadingStatus;
33
+ export let container = true;
34
+ export let scale: number | null = null;
35
+ export let min_width: number | undefined = undefined;
36
+ export let gradio: Gradio<{
37
+ change: never;
38
+ error: string;
39
+ upload: never;
40
+ clear: never;
41
+ select: SelectData;
42
+ clear_status: LoadingStatus;
43
+ delete: FileData;
44
+ download: FileData;
45
+ }>;
46
+ export let file_count: "single" | "multiple" | "directory";
47
+ export let file_types: string[] = ["file"];
48
+ export let input_ready: boolean;
49
+ export let allow_reordering = false;
50
+ let uploading = false;
51
+ $: input_ready = !uploading;
52
+
53
+ let old_value = value;
54
+ $: if (JSON.stringify(old_value) !== JSON.stringify(value)) {
55
+ gradio.dispatch("change");
56
+ old_value = value;
57
+ }
58
+
59
+ let dragging = false;
60
+ let pending_upload = false;
61
+ </script>
62
+
63
+ <Block
64
+ {visible}
65
+ variant={value ? "solid" : "dashed"}
66
+ border_mode={dragging ? "focus" : "base"}
67
+ padding={false}
68
+ {elem_id}
69
+ {elem_classes}
70
+ {container}
71
+ {scale}
72
+ {min_width}
73
+ allow_overflow={false}
74
+ >
75
+ <StatusTracker
76
+ autoscroll={gradio.autoscroll}
77
+ i18n={gradio.i18n}
78
+ {...loading_status}
79
+ status={pending_upload
80
+ ? "generating"
81
+ : loading_status?.status || "complete"}
82
+ on:clear_status={() => gradio.dispatch("clear_status", loading_status)}
83
+ />
84
+ {#if !interactive}
85
+ <File
86
+ on:select={({ detail }) => gradio.dispatch("select", detail)}
87
+ on:download={({ detail }) => gradio.dispatch("download", detail)}
88
+ selectable={_selectable}
89
+ {value}
90
+ {label}
91
+ {show_label}
92
+ {height}
93
+ i18n={gradio.i18n}
94
+ />
95
+ {:else}
96
+ <FileUpload
97
+ upload={(...args) => gradio.client.upload(...args)}
98
+ stream_handler={(...args) => gradio.client.stream(...args)}
99
+ {label}
100
+ {show_label}
101
+ {value}
102
+ {file_count}
103
+ {file_types}
104
+ selectable={_selectable}
105
+ {root}
106
+ {height}
107
+ {allow_reordering}
108
+ bind:uploading
109
+ max_file_size={gradio.max_file_size}
110
+ on:change={({ detail }) => {
111
+ value = detail;
112
+ }}
113
+ on:drag={({ detail }) => (dragging = detail)}
114
+ on:clear={() => gradio.dispatch("clear")}
115
+ on:select={({ detail }) => gradio.dispatch("select", detail)}
116
+ on:upload={() => gradio.dispatch("upload")}
117
+ on:error={({ detail }) => {
118
+ loading_status = loading_status || {};
119
+ loading_status.status = "error";
120
+ gradio.dispatch("error", detail);
121
+ }}
122
+ on:delete={({ detail }) => {
123
+ gradio.dispatch("delete", detail);
124
+ }}
125
+ i18n={gradio.i18n}
126
+ >
127
+ <UploadText i18n={gradio.i18n} type="file" />
128
+ </FileUpload>
129
+ {/if}
130
+ </Block>
5.49.1/file/package.json ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "@gradio/file",
3
+ "version": "0.13.0",
4
+ "description": "Gradio UI packages",
5
+ "type": "module",
6
+ "author": "",
7
+ "license": "ISC",
8
+ "private": false,
9
+ "dependencies": {
10
+ "@gradio/atoms": "workspace:^",
11
+ "@gradio/client": "workspace:^",
12
+ "@gradio/icons": "workspace:^",
13
+ "@gradio/statustracker": "workspace:^",
14
+ "@gradio/upload": "workspace:^",
15
+ "@gradio/utils": "workspace:^"
16
+ },
17
+ "devDependencies": {
18
+ "@gradio/preview": "workspace:^"
19
+ },
20
+ "main": "./Index.svelte",
21
+ "main_changeset": true,
22
+ "exports": {
23
+ ".": {
24
+ "gradio": "./Index.svelte",
25
+ "svelte": "./dist/Index.svelte",
26
+ "types": "./dist/Index.svelte.d.ts"
27
+ },
28
+ "./example": {
29
+ "gradio": "./Example.svelte",
30
+ "svelte": "./dist/Example.svelte",
31
+ "types": "./dist/Example.svelte.d.ts"
32
+ },
33
+ "./package.json": "./package.json"
34
+ },
35
+ "peerDependencies": {
36
+ "svelte": "^4.0.0"
37
+ },
38
+ "repository": {
39
+ "type": "git",
40
+ "url": "git+https://github.com/gradio-app/gradio.git",
41
+ "directory": "js/file"
42
+ }
43
+ }
5.49.1/file/shared/File.svelte ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import type { FileData } from "@gradio/client";
3
+ import { BlockLabel, Empty } from "@gradio/atoms";
4
+ import { File } from "@gradio/icons";
5
+ import FilePreview from "./FilePreview.svelte";
6
+ import type { I18nFormatter } from "@gradio/utils";
7
+
8
+ export let value: FileData | FileData[] | null = null;
9
+ export let label: string;
10
+ export let show_label = true;
11
+ export let selectable = false;
12
+ export let height: number | undefined = undefined;
13
+ export let i18n: I18nFormatter;
14
+ </script>
15
+
16
+ <BlockLabel
17
+ {show_label}
18
+ float={value === null}
19
+ Icon={File}
20
+ label={label || "File"}
21
+ />
22
+
23
+ {#if value && (Array.isArray(value) ? value.length > 0 : true)}
24
+ <FilePreview {i18n} {selectable} on:select on:download {value} {height} />
25
+ {:else}
26
+ <Empty unpadded_box={true} size="large"><File /></Empty>
27
+ {/if}
5.49.1/file/shared/FilePreview.svelte ADDED
@@ -0,0 +1,314 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import type { FileData } from "@gradio/client";
3
+ import { prettyBytes } from "./utils";
4
+ import { createEventDispatcher } from "svelte";
5
+ import type { I18nFormatter, SelectData } from "@gradio/utils";
6
+ import { DownloadLink } from "@gradio/atoms";
7
+
8
+ const dispatch = createEventDispatcher<{
9
+ select: SelectData;
10
+ change: FileData[] | FileData;
11
+ delete: FileData;
12
+ download: FileData;
13
+ }>();
14
+ export let value: FileData | FileData[];
15
+ export let selectable = false;
16
+ export let height: number | string | undefined = undefined;
17
+ export let i18n: I18nFormatter;
18
+ export let allow_reordering = false;
19
+
20
+ let dragging_index: number | null = null;
21
+ let drop_target_index: number | null = null;
22
+
23
+ function handle_drag_start(event: DragEvent, index: number): void {
24
+ dragging_index = index;
25
+ if (event.dataTransfer) {
26
+ event.dataTransfer.effectAllowed = "move";
27
+ event.dataTransfer.setData("text/plain", index.toString());
28
+ }
29
+ }
30
+
31
+ function handle_drag_over(event: DragEvent, index: number): void {
32
+ event.preventDefault();
33
+ if (index === normalized_files.length - 1) {
34
+ const rect = (event.currentTarget as HTMLElement).getBoundingClientRect();
35
+ const midY = rect.top + rect.height / 2;
36
+ drop_target_index =
37
+ event.clientY > midY ? normalized_files.length : index;
38
+ } else {
39
+ drop_target_index = index;
40
+ }
41
+ if (event.dataTransfer) {
42
+ event.dataTransfer.dropEffect = "move";
43
+ }
44
+ }
45
+
46
+ function handle_drag_end(event: DragEvent): void {
47
+ if (
48
+ !event.dataTransfer?.dropEffect ||
49
+ event.dataTransfer.dropEffect === "none"
50
+ ) {
51
+ dragging_index = null;
52
+ drop_target_index = null;
53
+ }
54
+ }
55
+
56
+ function handle_drop(event: DragEvent, index: number): void {
57
+ event.preventDefault();
58
+ if (dragging_index === null || dragging_index === index) return;
59
+
60
+ const files = Array.isArray(value) ? [...value] : [value];
61
+ const [removed] = files.splice(dragging_index, 1);
62
+ files.splice(
63
+ drop_target_index === normalized_files.length
64
+ ? normalized_files.length
65
+ : index,
66
+ 0,
67
+ removed
68
+ );
69
+
70
+ const new_value = Array.isArray(value) ? files : files[0];
71
+ dispatch("change", new_value);
72
+
73
+ dragging_index = null;
74
+ drop_target_index = null;
75
+ }
76
+
77
+ function split_filename(filename: string): [string, string] {
78
+ const last_dot = filename.lastIndexOf(".");
79
+ if (last_dot === -1) {
80
+ return [filename, ""];
81
+ }
82
+ return [filename.slice(0, last_dot), filename.slice(last_dot)];
83
+ }
84
+
85
+ $: normalized_files = (Array.isArray(value) ? value : [value]).map((file) => {
86
+ const [filename_stem, filename_ext] = split_filename(file.orig_name ?? "");
87
+ return {
88
+ ...file,
89
+ filename_stem,
90
+ filename_ext
91
+ };
92
+ });
93
+
94
+ function handle_row_click(
95
+ event: MouseEvent & { currentTarget: HTMLTableRowElement },
96
+ index: number
97
+ ): void {
98
+ const tr = event.currentTarget;
99
+ const should_select =
100
+ event.target === tr || // Only select if the click is on the row itself
101
+ (tr &&
102
+ tr.firstElementChild &&
103
+ event.composedPath().includes(tr.firstElementChild)); // Or if the click is on the name column
104
+
105
+ if (should_select) {
106
+ dispatch("select", { value: normalized_files[index].orig_name, index });
107
+ }
108
+ }
109
+
110
+ function remove_file(index: number): void {
111
+ const removed = normalized_files.splice(index, 1);
112
+ normalized_files = [...normalized_files];
113
+ value = normalized_files;
114
+ dispatch("delete", removed[0]);
115
+ dispatch("change", normalized_files);
116
+ }
117
+
118
+ function handle_download(file: FileData): void {
119
+ dispatch("download", file);
120
+ }
121
+
122
+ const is_browser = typeof window !== "undefined";
123
+ </script>
124
+
125
+ <div
126
+ class="file-preview-holder"
127
+ style:max-height={height
128
+ ? typeof height === "number"
129
+ ? height + "px"
130
+ : height
131
+ : "auto"}
132
+ >
133
+ <table class="file-preview">
134
+ <tbody>
135
+ {#each normalized_files as file, i (file.url)}
136
+ <tr
137
+ class="file"
138
+ class:selectable
139
+ class:dragging={dragging_index === i}
140
+ class:drop-target={drop_target_index === i ||
141
+ (i === normalized_files.length - 1 &&
142
+ drop_target_index === normalized_files.length)}
143
+ data-drop-target={drop_target_index === normalized_files.length &&
144
+ i === normalized_files.length - 1
145
+ ? "after"
146
+ : drop_target_index === i + 1
147
+ ? "after"
148
+ : "before"}
149
+ draggable={allow_reordering && normalized_files.length > 1}
150
+ on:click={(event) => {
151
+ handle_row_click(event, i);
152
+ }}
153
+ on:dragstart={(event) => handle_drag_start(event, i)}
154
+ on:dragenter|preventDefault
155
+ on:dragover={(event) => handle_drag_over(event, i)}
156
+ on:drop={(event) => handle_drop(event, i)}
157
+ on:dragend={handle_drag_end}
158
+ >
159
+ <td class="filename" aria-label={file.orig_name}>
160
+ {#if allow_reordering && normalized_files.length > 1}
161
+ <span class="drag-handle">⋮⋮</span>
162
+ {/if}
163
+ <span class="stem">{file.filename_stem}</span>
164
+ <span class="ext">{file.filename_ext}</span>
165
+ </td>
166
+
167
+ <td class="download">
168
+ {#if file.url}
169
+ <DownloadLink
170
+ href={file.url}
171
+ on:click={() => handle_download(file)}
172
+ download={is_browser && window.__is_colab__
173
+ ? null
174
+ : file.orig_name}
175
+ >
176
+ {@html file.size != null
177
+ ? prettyBytes(file.size)
178
+ : "(size unknown)"}&nbsp;&#8675;
179
+ </DownloadLink>
180
+ {:else}
181
+ {i18n("file.uploading")}
182
+ {/if}
183
+ </td>
184
+
185
+ {#if normalized_files.length > 1}
186
+ <td>
187
+ <button
188
+ class="label-clear-button"
189
+ aria-label="Remove this file"
190
+ on:click={() => {
191
+ remove_file(i);
192
+ }}
193
+ on:keydown={(event) => {
194
+ if (event.key === "Enter") {
195
+ remove_file(i);
196
+ }
197
+ }}
198
+
199
+ </button>
200
+ </td>
201
+ {/if}
202
+ </tr>
203
+ {/each}
204
+ </tbody>
205
+ </table>
206
+ </div>
207
+
208
+ <style>
209
+ .label-clear-button {
210
+ color: var(--body-text-color-subdued);
211
+ position: relative;
212
+ left: -3px;
213
+ }
214
+
215
+ .label-clear-button:hover {
216
+ color: var(--body-text-color);
217
+ }
218
+
219
+ .file-preview {
220
+ table-layout: fixed;
221
+ width: var(--size-full);
222
+ max-height: var(--size-60);
223
+ overflow-y: auto;
224
+ margin-top: var(--size-1);
225
+ color: var(--body-text-color);
226
+ }
227
+
228
+ .file-preview-holder {
229
+ overflow: auto;
230
+ }
231
+
232
+ .file {
233
+ display: flex;
234
+ width: var(--size-full);
235
+ }
236
+
237
+ .file > * {
238
+ padding: var(--size-1) var(--size-2-5);
239
+ }
240
+
241
+ .filename {
242
+ flex-grow: 1;
243
+ display: flex;
244
+ overflow: hidden;
245
+ }
246
+ .filename .stem {
247
+ overflow: hidden;
248
+ text-overflow: ellipsis;
249
+ white-space: nowrap;
250
+ }
251
+ .filename .ext {
252
+ white-space: nowrap;
253
+ }
254
+
255
+ .download {
256
+ min-width: 8rem;
257
+ width: 10%;
258
+ white-space: nowrap;
259
+ text-align: right;
260
+ }
261
+ .download:hover {
262
+ text-decoration: underline;
263
+ }
264
+ .download > :global(a) {
265
+ color: var(--link-text-color);
266
+ }
267
+
268
+ .download > :global(a:hover) {
269
+ color: var(--link-text-color-hover);
270
+ }
271
+ .download > :global(a:visited) {
272
+ color: var(--link-text-color-visited);
273
+ }
274
+ .download > :global(a:active) {
275
+ color: var(--link-text-color-active);
276
+ }
277
+ .selectable {
278
+ cursor: pointer;
279
+ }
280
+
281
+ tbody > tr:nth-child(even) {
282
+ background: var(--block-background-fill);
283
+ }
284
+
285
+ tbody > tr:nth-child(odd) {
286
+ background: var(--table-odd-background-fill);
287
+ }
288
+
289
+ .drag-handle {
290
+ cursor: grab;
291
+ color: var(--body-text-color-subdued);
292
+ padding-right: var(--size-2);
293
+ user-select: none;
294
+ }
295
+
296
+ .dragging {
297
+ opacity: 0.5;
298
+ cursor: grabbing;
299
+ }
300
+
301
+ .drop-target {
302
+ border-top: 2px solid var(--color-accent);
303
+ }
304
+
305
+ tr:last-child.drop-target[data-drop-target="before"] {
306
+ border-top: 2px solid var(--color-accent);
307
+ border-bottom: none;
308
+ }
309
+
310
+ tr:last-child.drop-target[data-drop-target="after"] {
311
+ border-top: none;
312
+ border-bottom: 2px solid var(--color-accent);
313
+ }
314
+ </style>
5.49.1/file/shared/FileUpload.svelte ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import { createEventDispatcher, tick } from "svelte";
3
+ import { Upload, ModifyUpload } from "@gradio/upload";
4
+ import type { FileData, Client } from "@gradio/client";
5
+ import { BlockLabel, IconButtonWrapper, IconButton } from "@gradio/atoms";
6
+ import { File, Clear, Upload as UploadIcon } from "@gradio/icons";
7
+
8
+ import FilePreview from "./FilePreview.svelte";
9
+ import type { I18nFormatter } from "@gradio/utils";
10
+
11
+ export let value: null | FileData | FileData[];
12
+
13
+ export let label: string;
14
+ export let show_label = true;
15
+ export let file_count: "single" | "multiple" | "directory" = "single";
16
+ export let file_types: string[] | null = null;
17
+ export let selectable = false;
18
+ export let root: string;
19
+ export let height: number | undefined = undefined;
20
+ export let i18n: I18nFormatter;
21
+ export let max_file_size: number | null = null;
22
+ export let upload: Client["upload"];
23
+ export let stream_handler: Client["stream"];
24
+ export let uploading = false;
25
+ export let allow_reordering = false;
26
+
27
+ async function handle_upload({
28
+ detail
29
+ }: CustomEvent<FileData | FileData[]>): Promise<void> {
30
+ if (Array.isArray(value)) {
31
+ value = [...value, ...(Array.isArray(detail) ? detail : [detail])];
32
+ } else if (value) {
33
+ value = [value, ...(Array.isArray(detail) ? detail : [detail])];
34
+ } else {
35
+ value = detail;
36
+ }
37
+ await tick();
38
+ dispatch("change", value);
39
+ dispatch("upload", detail);
40
+ }
41
+
42
+ function handle_clear(): void {
43
+ value = null;
44
+ dispatch("change", null);
45
+ dispatch("clear");
46
+ }
47
+
48
+ const dispatch = createEventDispatcher<{
49
+ change: FileData[] | FileData | null;
50
+ clear: undefined;
51
+ drag: boolean;
52
+ upload: FileData[] | FileData;
53
+ load: FileData[] | FileData;
54
+ error: string;
55
+ }>();
56
+
57
+ let dragging = false;
58
+ $: dispatch("drag", dragging);
59
+ </script>
60
+
61
+ <BlockLabel {show_label} Icon={File} float={!value} label={label || "File"} />
62
+
63
+ {#if value && (Array.isArray(value) ? value.length > 0 : true)}
64
+ <IconButtonWrapper>
65
+ {#if !(file_count === "single" && (Array.isArray(value) ? value.length > 0 : value !== null))}
66
+ <IconButton Icon={UploadIcon} label={i18n("common.upload")}>
67
+ <Upload
68
+ icon_upload={true}
69
+ on:load={handle_upload}
70
+ filetype={file_types}
71
+ {file_count}
72
+ {max_file_size}
73
+ {root}
74
+ bind:dragging
75
+ bind:uploading
76
+ on:error
77
+ {stream_handler}
78
+ {upload}
79
+ />
80
+ </IconButton>
81
+ {/if}
82
+ <IconButton
83
+ Icon={Clear}
84
+ label={i18n("common.clear")}
85
+ on:click={(event) => {
86
+ dispatch("clear");
87
+ event.stopPropagation();
88
+ handle_clear();
89
+ }}
90
+ />
91
+ </IconButtonWrapper>
92
+
93
+ <FilePreview
94
+ {i18n}
95
+ on:select
96
+ {selectable}
97
+ {value}
98
+ {height}
99
+ on:change
100
+ on:delete
101
+ {allow_reordering}
102
+ />
103
+ {:else}
104
+ <Upload
105
+ on:load={handle_upload}
106
+ filetype={file_types}
107
+ {file_count}
108
+ {max_file_size}
109
+ {root}
110
+ bind:dragging
111
+ bind:uploading
112
+ on:error
113
+ {stream_handler}
114
+ {upload}
115
+ {height}
116
+ >
117
+ <slot />
118
+ </Upload>
119
+ {/if}
5.49.1/file/shared/utils.ts ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type { FileData } from "@gradio/client";
2
+
3
+ export const prettyBytes = (bytes: number): string => {
4
+ let units = ["B", "KB", "MB", "GB", "PB"];
5
+ let i = 0;
6
+ while (bytes > 1024) {
7
+ bytes /= 1024;
8
+ i++;
9
+ }
10
+ let unit = units[i];
11
+ return bytes.toFixed(1) + "&nbsp;" + unit;
12
+ };