@gradio/uploadbutton 0.5.8 → 0.6.1
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 +55 -0
- package/Index.svelte +6 -0
- package/package.json +8 -5
- package/shared/UploadButton.svelte +13 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,60 @@
|
|
|
1
1
|
# @gradio/uploadbutton
|
|
2
2
|
|
|
3
|
+
## 0.6.1
|
|
4
|
+
|
|
5
|
+
### Fixes
|
|
6
|
+
|
|
7
|
+
- [#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!
|
|
8
|
+
|
|
9
|
+
### Dependency updates
|
|
10
|
+
|
|
11
|
+
- @gradio/client@0.18.0
|
|
12
|
+
- @gradio/upload@0.10.0
|
|
13
|
+
- @gradio/utils@0.4.1
|
|
14
|
+
- @gradio/button@0.2.33
|
|
15
|
+
|
|
16
|
+
## 0.6.0
|
|
17
|
+
|
|
18
|
+
### Highlights
|
|
19
|
+
|
|
20
|
+
#### Setting File Upload Limits ([#7909](https://github.com/gradio-app/gradio/pull/7909) [`2afca65`](https://github.com/gradio-app/gradio/commit/2afca6541912b37dc84f447c7ad4af21607d7c72))
|
|
21
|
+
|
|
22
|
+
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).
|
|
23
|
+
|
|
24
|
+
The following code snippet sets a max file size of 5 megabytes.
|
|
25
|
+
|
|
26
|
+
```python
|
|
27
|
+
import gradio as gr
|
|
28
|
+
|
|
29
|
+
demo = gr.Interface(lambda x: x, "image", "image")
|
|
30
|
+
|
|
31
|
+
demo.launch(max_file_size="5mb")
|
|
32
|
+
# or
|
|
33
|
+
demo.launch(max_file_size=5 * gr.FileSize.MB)
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+

|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
#### Error states can now be cleared
|
|
40
|
+
|
|
41
|
+
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.
|
|
42
|
+
|
|
43
|
+

|
|
44
|
+
|
|
45
|
+
Thanks @freddyaboulton!
|
|
46
|
+
|
|
47
|
+
### Fixes
|
|
48
|
+
|
|
49
|
+
- [#8066](https://github.com/gradio-app/gradio/pull/8066) [`624f9b9`](https://github.com/gradio-app/gradio/commit/624f9b9477f74a581a6c14119234f9efdfcda398) - make gradio dev tools a local dependency rather than bundling. Thanks @pngwn!
|
|
50
|
+
|
|
51
|
+
### Dependency updates
|
|
52
|
+
|
|
53
|
+
- @gradio/client@0.17.0
|
|
54
|
+
- @gradio/button@0.2.32
|
|
55
|
+
- @gradio/upload@0.9.0
|
|
56
|
+
- @gradio/utils@0.4.0
|
|
57
|
+
|
|
3
58
|
## 0.5.8
|
|
4
59
|
|
|
5
60
|
### Dependency updates
|
package/Index.svelte
CHANGED
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
change: never;
|
|
25
25
|
upload: never;
|
|
26
26
|
click: never;
|
|
27
|
+
error: string;
|
|
27
28
|
}>;
|
|
28
29
|
export let interactive: boolean;
|
|
29
30
|
|
|
@@ -53,9 +54,14 @@
|
|
|
53
54
|
{disabled}
|
|
54
55
|
{variant}
|
|
55
56
|
{label}
|
|
57
|
+
max_file_size={gradio.max_file_size}
|
|
56
58
|
on:click={() => gradio.dispatch("click")}
|
|
57
59
|
on:change={({ detail }) => handle_event(detail, "change")}
|
|
58
60
|
on:upload={({ detail }) => handle_event(detail, "upload")}
|
|
61
|
+
on:error={({ detail }) => {
|
|
62
|
+
gradio.dispatch("error", detail);
|
|
63
|
+
}}
|
|
64
|
+
upload={gradio.client.upload}
|
|
59
65
|
>
|
|
60
66
|
{label ? gradio.i18n(label) : ""}
|
|
61
67
|
</UploadButton>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gradio/uploadbutton",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "Gradio UI packages",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "",
|
|
@@ -13,9 +13,12 @@
|
|
|
13
13
|
},
|
|
14
14
|
"main": "./Index.svelte",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@gradio/button": "^0.2.
|
|
17
|
-
"@gradio/client": "^0.
|
|
18
|
-
"@gradio/
|
|
19
|
-
"@gradio/
|
|
16
|
+
"@gradio/button": "^0.2.33",
|
|
17
|
+
"@gradio/client": "^0.18.0",
|
|
18
|
+
"@gradio/utils": "^0.4.1",
|
|
19
|
+
"@gradio/upload": "^0.10.0"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@gradio/preview": "^0.9.0"
|
|
20
23
|
}
|
|
21
24
|
}
|
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import { tick, createEventDispatcher
|
|
2
|
+
import { tick, createEventDispatcher } from "svelte";
|
|
3
3
|
import { BaseButton } from "@gradio/button";
|
|
4
|
-
import {
|
|
5
|
-
upload,
|
|
6
|
-
prepare_files,
|
|
7
|
-
type FileData,
|
|
8
|
-
type upload_files
|
|
9
|
-
} from "@gradio/client";
|
|
4
|
+
import { prepare_files, type FileData, type Client } from "@gradio/client";
|
|
10
5
|
|
|
11
6
|
export let elem_id = "";
|
|
12
7
|
export let elem_classes: string[] = [];
|
|
@@ -22,12 +17,11 @@
|
|
|
22
17
|
export let min_width: number | undefined = undefined;
|
|
23
18
|
export let variant: "primary" | "secondary" | "stop" = "secondary";
|
|
24
19
|
export let disabled = false;
|
|
20
|
+
export let max_file_size: number | null = null;
|
|
21
|
+
export let upload: Client["upload"];
|
|
25
22
|
|
|
26
23
|
const dispatch = createEventDispatcher();
|
|
27
24
|
|
|
28
|
-
// Needed for wasm support
|
|
29
|
-
const upload_fn = getContext<typeof upload_files>("upload_files");
|
|
30
|
-
|
|
31
25
|
let hidden_upload: HTMLInputElement;
|
|
32
26
|
let accept_file_types: string | null;
|
|
33
27
|
|
|
@@ -50,6 +44,7 @@
|
|
|
50
44
|
|
|
51
45
|
async function load_files(files: FileList): Promise<void> {
|
|
52
46
|
let _files: File[] = Array.from(files);
|
|
47
|
+
|
|
53
48
|
if (!files.length) {
|
|
54
49
|
return;
|
|
55
50
|
}
|
|
@@ -59,9 +54,14 @@
|
|
|
59
54
|
let all_file_data = await prepare_files(_files);
|
|
60
55
|
await tick();
|
|
61
56
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
57
|
+
try {
|
|
58
|
+
all_file_data = (
|
|
59
|
+
await upload(all_file_data, root, undefined, max_file_size ?? Infinity)
|
|
60
|
+
)?.filter((x) => x !== null) as FileData[];
|
|
61
|
+
} catch (e) {
|
|
62
|
+
dispatch("error", (e as Error).message);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
65
|
value = file_count === "single" ? all_file_data?.[0] : all_file_data;
|
|
66
66
|
dispatch("change", value);
|
|
67
67
|
dispatch("upload", value);
|