@gradio/upload 0.8.4 → 0.9.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 CHANGED
@@ -1,5 +1,57 @@
1
1
  # @gradio/upload
2
2
 
3
+ ## 0.9.0
4
+
5
+ ### Highlights
6
+
7
+ #### Setting File Upload Limits ([#7909](https://github.com/gradio-app/gradio/pull/7909) [`2afca65`](https://github.com/gradio-app/gradio/commit/2afca6541912b37dc84f447c7ad4af21607d7c72))
8
+
9
+ 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).
10
+
11
+ The following code snippet sets a max file size of 5 megabytes.
12
+
13
+ ```python
14
+ import gradio as gr
15
+
16
+ demo = gr.Interface(lambda x: x, "image", "image")
17
+
18
+ demo.launch(max_file_size="5mb")
19
+ # or
20
+ demo.launch(max_file_size=5 * gr.FileSize.MB)
21
+ ```
22
+
23
+ ![max_file_size_upload](https://github.com/gradio-app/gradio/assets/41651716/7547330c-a082-4901-a291-3f150a197e45)
24
+
25
+
26
+ #### Error states can now be cleared
27
+
28
+ 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.
29
+
30
+ ![error_modal_calculator](https://github.com/gradio-app/gradio/assets/41651716/16cb071c-accd-45a6-9c18-0dea27d4bd98)
31
+
32
+ Thanks @freddyaboulton!
33
+
34
+ ### Dependency updates
35
+
36
+ - @gradio/atoms@0.7.1
37
+ - @gradio/client@0.17.0
38
+ - @gradio/upload@0.9.0
39
+ - @gradio/utils@0.4.0
40
+
41
+ ## 0.8.5
42
+
43
+ ### Fixes
44
+
45
+ - [#8002](https://github.com/gradio-app/gradio/pull/8002) [`8903415`](https://github.com/gradio-app/gradio/commit/8903415e49b1526d31ff454b2235ea238e319c2c) - Add show_progress prop to Upload Component to bring back upload progress animation. Thanks @freddyaboulton!
46
+
47
+ ### Dependency updates
48
+
49
+ - @gradio/utils@0.3.2
50
+ - @gradio/client@0.16.0
51
+ - @gradio/upload@0.8.5
52
+ - @gradio/atoms@0.7.0
53
+ - @gradio/icons@0.4.0
54
+
3
55
  ## 0.8.4
4
56
 
5
57
  ### Dependency updates
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "@gradio/upload",
3
- "version": "0.8.4",
3
+ "version": "0.9.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/atoms": "^0.6.2",
11
- "@gradio/icons": "^0.3.4",
12
- "@gradio/client": "^0.15.1",
13
- "@gradio/utils": "^0.3.1",
14
- "@gradio/wasm": "^0.10.0",
15
- "@gradio/upload": "^0.8.4"
10
+ "@gradio/atoms": "^0.7.1",
11
+ "@gradio/icons": "^0.4.0",
12
+ "@gradio/upload": "^0.9.0",
13
+ "@gradio/client": "^0.17.0",
14
+ "@gradio/utils": "^0.4.0",
15
+ "@gradio/wasm": "^0.10.0"
16
16
  },
17
17
  "main_changeset": true,
18
18
  "exports": {
package/src/Upload.svelte CHANGED
@@ -17,6 +17,8 @@
17
17
  export let format: "blob" | "file" = "file";
18
18
  export let uploading = false;
19
19
  export let hidden_upload: HTMLInputElement | null = null;
20
+ export let show_progress = true;
21
+ export let max_file_size: number | null = null;
20
22
 
21
23
  let upload_id: string;
22
24
  let file_data: FileData[];
@@ -82,10 +84,22 @@
82
84
  await tick();
83
85
  upload_id = Math.random().toString(36).substring(2, 15);
84
86
  uploading = true;
85
- const _file_data = await upload(file_data, root, upload_id, upload_fn);
86
- dispatch("load", file_count === "single" ? _file_data?.[0] : _file_data);
87
- uploading = false;
88
- return _file_data || [];
87
+ try {
88
+ const _file_data = await upload(
89
+ file_data,
90
+ root,
91
+ upload_id,
92
+ max_file_size ?? Infinity,
93
+ upload_fn
94
+ );
95
+ dispatch("load", file_count === "single" ? _file_data?.[0] : _file_data);
96
+ uploading = false;
97
+ return _file_data || [];
98
+ } catch (e) {
99
+ dispatch("error", (e as Error).message);
100
+ uploading = false;
101
+ return [];
102
+ }
89
103
  }
90
104
 
91
105
  export async function load_files(
@@ -185,7 +199,7 @@
185
199
  >
186
200
  <slot />
187
201
  </button>
188
- {:else if uploading && !hidden_upload}
202
+ {:else if uploading && show_progress}
189
203
  {#if !hidden}
190
204
  <UploadProgress {root} {upload_id} files={file_data} />
191
205
  {/if}
@@ -1,6 +1,11 @@
1
1
  <script lang="ts">
2
2
  import { FileData } from "@gradio/client";
3
- import { onMount, createEventDispatcher, getContext } from "svelte";
3
+ import {
4
+ onMount,
5
+ createEventDispatcher,
6
+ getContext,
7
+ onDestroy
8
+ } from "svelte";
4
9
 
5
10
  type FileDataWithProgress = FileData & { progress: number };
6
11
 
@@ -56,6 +61,9 @@
56
61
  }
57
62
  };
58
63
  });
64
+ onDestroy(() => {
65
+ if (event_source != null || event_source != undefined) event_source.close();
66
+ });
59
67
 
60
68
  function calculateTotalProgress(files: FileData[]): number {
61
69
  let totalProgress = 0;