@gradio/upload 0.8.5 → 0.10.0
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.
- package/CHANGELOG.md +58 -0
- package/package.json +6 -6
- package/src/Upload.svelte +22 -10
- package/src/UploadProgress.svelte +14 -9
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,63 @@
|
|
1
1
|
# @gradio/upload
|
2
2
|
|
3
|
+
## 0.10.0
|
4
|
+
|
5
|
+
### Features
|
6
|
+
|
7
|
+
- [#8121](https://github.com/gradio-app/gradio/pull/8121) [`f5b710c`](https://github.com/gradio-app/gradio/commit/f5b710c919b0ce604ea955f0d5f4faa91095ca4a) - chore(deps): update dependency eslint to v9. Thanks @renovate!
|
8
|
+
- [#8209](https://github.com/gradio-app/gradio/pull/8209) [`b9afe93`](https://github.com/gradio-app/gradio/commit/b9afe93915401df5bd6737c89395c2477acfa585) - Rename `eventSource_Factory` and `fetch_implementation`. Thanks @hannahblair!
|
9
|
+
|
10
|
+
### Fixes
|
11
|
+
|
12
|
+
- [#8179](https://github.com/gradio-app/gradio/pull/8179) [`6a218b4`](https://github.com/gradio-app/gradio/commit/6a218b4148095aaa0c58d8c20973ba01c8764fc2) - rework upload to be a class method + pass client into each component. Thanks @pngwn!
|
13
|
+
- [#8118](https://github.com/gradio-app/gradio/pull/8118) [`7aca673`](https://github.com/gradio-app/gradio/commit/7aca673b38a087533524b2fd8dd3a03e0e4bacfe) - Add eventsource polyfill for Node.js and browser environments. Thanks @hannahblair!
|
14
|
+
|
15
|
+
### Dependency updates
|
16
|
+
|
17
|
+
- @gradio/atoms@0.7.2
|
18
|
+
- @gradio/client@0.18.0
|
19
|
+
- @gradio/upload@0.10.0
|
20
|
+
- @gradio/utils@0.4.1
|
21
|
+
- @gradio/wasm@0.10.1
|
22
|
+
|
23
|
+
## 0.9.0
|
24
|
+
|
25
|
+
### Highlights
|
26
|
+
|
27
|
+
#### Setting File Upload Limits ([#7909](https://github.com/gradio-app/gradio/pull/7909) [`2afca65`](https://github.com/gradio-app/gradio/commit/2afca6541912b37dc84f447c7ad4af21607d7c72))
|
28
|
+
|
29
|
+
We have added a `max_file_size` size parameter to `launch()` that limits to size of files uploaded to the server. This limit applies to each individual file. This parameter can be specified as a string or an integer (corresponding to the size in bytes).
|
30
|
+
|
31
|
+
The following code snippet sets a max file size of 5 megabytes.
|
32
|
+
|
33
|
+
```python
|
34
|
+
import gradio as gr
|
35
|
+
|
36
|
+
demo = gr.Interface(lambda x: x, "image", "image")
|
37
|
+
|
38
|
+
demo.launch(max_file_size="5mb")
|
39
|
+
# or
|
40
|
+
demo.launch(max_file_size=5 * gr.FileSize.MB)
|
41
|
+
```
|
42
|
+
|
43
|
+

|
44
|
+
|
45
|
+
|
46
|
+
#### Error states can now be cleared
|
47
|
+
|
48
|
+
When a component encounters an error, the error state shown in the UI can now be cleared by clicking on the `x` icon in the top right of the component. This applies to all types of errors, whether it's raised in the UI or the server.
|
49
|
+
|
50
|
+

|
51
|
+
|
52
|
+
Thanks @freddyaboulton!
|
53
|
+
|
54
|
+
### Dependency updates
|
55
|
+
|
56
|
+
- @gradio/atoms@0.7.1
|
57
|
+
- @gradio/client@0.17.0
|
58
|
+
- @gradio/upload@0.9.0
|
59
|
+
- @gradio/utils@0.4.0
|
60
|
+
|
3
61
|
## 0.8.5
|
4
62
|
|
5
63
|
### Fixes
|
package/package.json
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
{
|
2
2
|
"name": "@gradio/upload",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.10.0",
|
4
4
|
"description": "Gradio UI packages",
|
5
5
|
"type": "module",
|
6
6
|
"main": "src/index.ts",
|
7
7
|
"author": "",
|
8
8
|
"license": "ISC",
|
9
9
|
"dependencies": {
|
10
|
+
"@gradio/client": "^0.18.0",
|
11
|
+
"@gradio/atoms": "^0.7.2",
|
10
12
|
"@gradio/icons": "^0.4.0",
|
11
|
-
"@gradio/
|
12
|
-
"@gradio/
|
13
|
-
"@gradio/
|
14
|
-
"@gradio/utils": "^0.3.2",
|
15
|
-
"@gradio/wasm": "^0.10.0"
|
13
|
+
"@gradio/upload": "^0.10.0",
|
14
|
+
"@gradio/utils": "^0.4.1",
|
15
|
+
"@gradio/wasm": "^0.10.1"
|
16
16
|
},
|
17
17
|
"main_changeset": true,
|
18
18
|
"exports": {
|
package/src/Upload.svelte
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
<script lang="ts">
|
2
2
|
import { createEventDispatcher, tick, getContext } from "svelte";
|
3
3
|
import type { FileData } from "@gradio/client";
|
4
|
-
import {
|
4
|
+
import { prepare_files, type Client } from "@gradio/client";
|
5
5
|
import { _ } from "svelte-i18n";
|
6
6
|
import UploadProgress from "./UploadProgress.svelte";
|
7
7
|
|
@@ -18,14 +18,14 @@
|
|
18
18
|
export let uploading = false;
|
19
19
|
export let hidden_upload: HTMLInputElement | null = null;
|
20
20
|
export let show_progress = true;
|
21
|
+
export let max_file_size: number | null = null;
|
22
|
+
export let upload: Client["upload"];
|
23
|
+
export let stream_handler: Client["stream_factory"];
|
21
24
|
|
22
25
|
let upload_id: string;
|
23
26
|
let file_data: FileData[];
|
24
27
|
let accept_file_types: string | null;
|
25
28
|
|
26
|
-
// Needed for wasm support
|
27
|
-
const upload_fn = getContext<typeof upload_files>("upload_files");
|
28
|
-
|
29
29
|
const dispatch = createEventDispatcher();
|
30
30
|
const validFileTypes = ["image", "video", "audio", "text", "file"];
|
31
31
|
const processFileType = (type: string): string => {
|
@@ -83,10 +83,21 @@
|
|
83
83
|
await tick();
|
84
84
|
upload_id = Math.random().toString(36).substring(2, 15);
|
85
85
|
uploading = true;
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
86
|
+
try {
|
87
|
+
const _file_data = await upload(
|
88
|
+
file_data,
|
89
|
+
root,
|
90
|
+
upload_id,
|
91
|
+
max_file_size ?? Infinity
|
92
|
+
);
|
93
|
+
dispatch("load", file_count === "single" ? _file_data?.[0] : _file_data);
|
94
|
+
uploading = false;
|
95
|
+
return _file_data || [];
|
96
|
+
} catch (e) {
|
97
|
+
dispatch("error", (e as Error).message);
|
98
|
+
uploading = false;
|
99
|
+
return [];
|
100
|
+
}
|
90
101
|
}
|
91
102
|
|
92
103
|
export async function load_files(
|
@@ -96,7 +107,8 @@
|
|
96
107
|
return;
|
97
108
|
}
|
98
109
|
let _files: File[] = files.map(
|
99
|
-
(f) =>
|
110
|
+
(f) =>
|
111
|
+
new File([f], f instanceof File ? f.name : "file", { type: f.type })
|
100
112
|
);
|
101
113
|
file_data = await prepare_files(_files);
|
102
114
|
return await handle_upload(file_data);
|
@@ -188,7 +200,7 @@
|
|
188
200
|
</button>
|
189
201
|
{:else if uploading && show_progress}
|
190
202
|
{#if !hidden}
|
191
|
-
<UploadProgress {root} {upload_id} files={file_data} />
|
203
|
+
<UploadProgress {root} {upload_id} files={file_data} {stream_handler} />
|
192
204
|
{/if}
|
193
205
|
{:else}
|
194
206
|
<button
|
@@ -1,14 +1,15 @@
|
|
1
1
|
<script lang="ts">
|
2
|
-
import { FileData } from "@gradio/client";
|
3
|
-
import { onMount, createEventDispatcher,
|
2
|
+
import { FileData, type Client } from "@gradio/client";
|
3
|
+
import { onMount, createEventDispatcher, onDestroy } from "svelte";
|
4
4
|
|
5
5
|
type FileDataWithProgress = FileData & { progress: number };
|
6
6
|
|
7
7
|
export let upload_id: string;
|
8
8
|
export let root: string;
|
9
9
|
export let files: FileData[];
|
10
|
+
export let stream_handler: Client["stream_factory"];
|
10
11
|
|
11
|
-
let
|
12
|
+
let stream: ReturnType<Client["stream_factory"]>;
|
12
13
|
let progress = false;
|
13
14
|
let current_file_upload: FileDataWithProgress;
|
14
15
|
let file_to_display: FileDataWithProgress;
|
@@ -36,19 +37,20 @@
|
|
36
37
|
return (file.progress * 100) / (file.size || 0) || 0;
|
37
38
|
}
|
38
39
|
|
39
|
-
const EventSource_factory = getContext<(url: URL) => EventSource>(
|
40
|
-
"EventSource_factory"
|
41
|
-
);
|
42
40
|
onMount(() => {
|
43
|
-
|
41
|
+
stream = stream_handler(
|
44
42
|
new URL(`${root}/upload_progress?upload_id=${upload_id}`)
|
45
43
|
);
|
44
|
+
|
45
|
+
if (stream == null) {
|
46
|
+
throw new Error("Event source is not defined");
|
47
|
+
}
|
46
48
|
// Event listener for progress updates
|
47
|
-
|
49
|
+
stream.onmessage = async function (event) {
|
48
50
|
const _data = JSON.parse(event.data);
|
49
51
|
if (!progress) progress = true;
|
50
52
|
if (_data.msg === "done") {
|
51
|
-
|
53
|
+
stream?.close();
|
52
54
|
dispatch("done");
|
53
55
|
} else {
|
54
56
|
current_file_upload = _data;
|
@@ -56,6 +58,9 @@
|
|
56
58
|
}
|
57
59
|
};
|
58
60
|
});
|
61
|
+
onDestroy(() => {
|
62
|
+
if (stream != null || stream != undefined) stream.close();
|
63
|
+
});
|
59
64
|
|
60
65
|
function calculateTotalProgress(files: FileData[]): number {
|
61
66
|
let totalProgress = 0;
|