@gradio/upload 0.8.5 → 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,43 @@
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
+
3
41
  ## 0.8.5
4
42
 
5
43
  ### Fixes
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@gradio/upload",
3
- "version": "0.8.5",
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.7.1",
10
11
  "@gradio/icons": "^0.4.0",
11
- "@gradio/atoms": "^0.7.0",
12
- "@gradio/client": "^0.16.0",
13
- "@gradio/upload": "^0.8.5",
14
- "@gradio/utils": "^0.3.2",
12
+ "@gradio/upload": "^0.9.0",
13
+ "@gradio/client": "^0.17.0",
14
+ "@gradio/utils": "^0.4.0",
15
15
  "@gradio/wasm": "^0.10.0"
16
16
  },
17
17
  "main_changeset": true,
package/src/Upload.svelte CHANGED
@@ -18,6 +18,7 @@
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;
21
22
 
22
23
  let upload_id: string;
23
24
  let file_data: FileData[];
@@ -83,10 +84,22 @@
83
84
  await tick();
84
85
  upload_id = Math.random().toString(36).substring(2, 15);
85
86
  uploading = true;
86
- const _file_data = await upload(file_data, root, upload_id, upload_fn);
87
- dispatch("load", file_count === "single" ? _file_data?.[0] : _file_data);
88
- uploading = false;
89
- 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
+ }
90
103
  }
91
104
 
92
105
  export async function load_files(
@@ -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;