@gradio/image 0.16.0-beta.4 → 0.16.0-beta.6
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 +22 -0
- package/dist/shared/ImageUploader.svelte +8 -3
- package/dist/shared/ImageUploader.svelte.d.ts +2 -1
- package/dist/shared/Webcam.svelte +15 -8
- package/dist/shared/Webcam.svelte.d.ts +3 -2
- package/dist/shared/types.d.ts +4 -0
- package/dist/shared/types.js +1 -0
- package/package.json +6 -6
- package/shared/ImageUploader.svelte +9 -3
- package/shared/Webcam.svelte +18 -11
- package/shared/types.ts +4 -0
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,27 @@
|
|
1
1
|
# @gradio/image
|
2
2
|
|
3
|
+
## 0.16.0-beta.6
|
4
|
+
|
5
|
+
### Features
|
6
|
+
|
7
|
+
- [#9483](https://github.com/gradio-app/gradio/pull/9483) [`8dc7c12`](https://github.com/gradio-app/gradio/commit/8dc7c12389311b60efcde1b9d3e3668a34d2dc00) - Send Streaming data over Websocket if possible. Also support base64 output format for images. Thanks @freddyaboulton!
|
8
|
+
|
9
|
+
### Dependency updates
|
10
|
+
|
11
|
+
- @gradio/statustracker@0.8.0-beta.4
|
12
|
+
- @gradio/atoms@0.9.0-beta.4
|
13
|
+
- @gradio/client@1.6.0-beta.4
|
14
|
+
- @gradio/upload@0.13.0-beta.6
|
15
|
+
|
16
|
+
## 0.16.0-beta.5
|
17
|
+
|
18
|
+
### Dependency updates
|
19
|
+
|
20
|
+
- @gradio/upload@0.13.0-beta.5
|
21
|
+
- @gradio/statustracker@0.8.0-beta.3
|
22
|
+
- @gradio/icons@0.8.0-beta.3
|
23
|
+
- @gradio/atoms@0.9.0-beta.3
|
24
|
+
|
3
25
|
## 0.16.0-beta.4
|
4
26
|
|
5
27
|
### Dependency updates
|
@@ -10,7 +10,7 @@ import { FileData } from "@gradio/client";
|
|
10
10
|
import ClearImage from "./ClearImage.svelte";
|
11
11
|
import { SelectSource } from "@gradio/atoms";
|
12
12
|
import Image from "./Image.svelte";
|
13
|
-
export let value;
|
13
|
+
export let value = null;
|
14
14
|
export let label = void 0;
|
15
15
|
export let show_label;
|
16
16
|
export let sources = ["upload", "clipboard", "webcam"];
|
@@ -41,6 +41,13 @@ function handle_clear() {
|
|
41
41
|
dispatch("change", null);
|
42
42
|
}
|
43
43
|
async function handle_save(img_blob, event) {
|
44
|
+
if (event === "stream") {
|
45
|
+
dispatch("stream", {
|
46
|
+
value: { url: img_blob },
|
47
|
+
is_value_data: true
|
48
|
+
});
|
49
|
+
return;
|
50
|
+
}
|
44
51
|
pending = true;
|
45
52
|
const f = await upload_input.load_files([
|
46
53
|
new File([img_blob], `image/${streaming ? "jpeg" : "png"}`)
|
@@ -49,8 +56,6 @@ async function handle_save(img_blob, event) {
|
|
49
56
|
value = f?.[0] || null;
|
50
57
|
await tick();
|
51
58
|
dispatch("change");
|
52
|
-
} else {
|
53
|
-
dispatch("stream", { value: f?.[0] || null, is_value_data: true });
|
54
59
|
}
|
55
60
|
pending = false;
|
56
61
|
}
|
@@ -1,9 +1,10 @@
|
|
1
1
|
import { SvelteComponent } from "svelte";
|
2
2
|
import { type SelectData, type I18nFormatter, type ValueData } from "@gradio/utils";
|
3
3
|
import { FileData, type Client } from "@gradio/client";
|
4
|
+
import type { Base64File } from "./types";
|
4
5
|
declare const __propDef: {
|
5
6
|
props: {
|
6
|
-
value
|
7
|
+
value?: (null | FileData | Base64File) | undefined;
|
7
8
|
label?: string | undefined;
|
8
9
|
show_label: boolean;
|
9
10
|
sources?: ("upload" | "clipboard" | "microphone" | "webcam" | null)[] | undefined;
|
@@ -47,7 +47,16 @@ export let i18n;
|
|
47
47
|
export let upload;
|
48
48
|
export let value = null;
|
49
49
|
const dispatch = createEventDispatcher();
|
50
|
-
onMount(() =>
|
50
|
+
onMount(() => {
|
51
|
+
canvas = document.createElement("canvas");
|
52
|
+
if (streaming && mode === "image") {
|
53
|
+
window.setInterval(() => {
|
54
|
+
if (video_source && !pending) {
|
55
|
+
take_picture();
|
56
|
+
}
|
57
|
+
}, stream_every * 1e3);
|
58
|
+
}
|
59
|
+
});
|
51
60
|
const handle_device_change = async (event) => {
|
52
61
|
const target = event.target;
|
53
62
|
const device_id = target.value;
|
@@ -102,6 +111,11 @@ function take_picture() {
|
|
102
111
|
if (streaming && (!recording || stream_state === "waiting")) {
|
103
112
|
return;
|
104
113
|
}
|
114
|
+
if (streaming) {
|
115
|
+
const image_data = canvas.toDataURL("image/jpeg");
|
116
|
+
dispatch("stream", image_data);
|
117
|
+
return;
|
118
|
+
}
|
105
119
|
canvas.toBlob(
|
106
120
|
(blob) => {
|
107
121
|
dispatch(streaming ? "stream" : "capture", blob);
|
@@ -179,13 +193,6 @@ function record_video_or_photo() {
|
|
179
193
|
value = null;
|
180
194
|
}
|
181
195
|
}
|
182
|
-
if (streaming && mode === "image") {
|
183
|
-
window.setInterval(() => {
|
184
|
-
if (video_source && !pending) {
|
185
|
-
take_picture();
|
186
|
-
}
|
187
|
-
}, stream_every * 1e3);
|
188
|
-
}
|
189
196
|
let options_open = false;
|
190
197
|
export function click_outside(node, cb) {
|
191
198
|
const handle_click = (event) => {
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import { SvelteComponent } from "svelte";
|
2
2
|
import type { I18nFormatter } from "@gradio/utils";
|
3
3
|
import { type FileData, type Client } from "@gradio/client";
|
4
|
+
import type { Base64File } from "./types";
|
4
5
|
declare const __propDef: {
|
5
6
|
props: {
|
6
7
|
modify_stream?: ((state: "open" | "closed" | "waiting") => void) | undefined;
|
@@ -14,11 +15,11 @@ declare const __propDef: {
|
|
14
15
|
include_audio: boolean;
|
15
16
|
i18n: I18nFormatter;
|
16
17
|
upload: Client["upload"];
|
17
|
-
value?: (FileData | null) | undefined;
|
18
|
+
value?: (FileData | null | Base64File) | undefined;
|
18
19
|
click_outside?: ((node: Node, cb: any) => any) | undefined;
|
19
20
|
};
|
20
21
|
events: {
|
21
|
-
stream: CustomEvent<
|
22
|
+
stream: CustomEvent<string | Blob>;
|
22
23
|
capture: CustomEvent<Blob | FileData | null>;
|
23
24
|
error: CustomEvent<string>;
|
24
25
|
start_recording: CustomEvent<undefined>;
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@gradio/image",
|
3
|
-
"version": "0.16.0-beta.
|
3
|
+
"version": "0.16.0-beta.6",
|
4
4
|
"description": "Gradio UI packages",
|
5
5
|
"type": "module",
|
6
6
|
"author": "",
|
@@ -10,11 +10,11 @@
|
|
10
10
|
"cropperjs": "^1.5.12",
|
11
11
|
"lazy-brush": "^1.0.1",
|
12
12
|
"resize-observer-polyfill": "^1.5.1",
|
13
|
-
"@gradio/atoms": "^0.9.0-beta.
|
14
|
-
"@gradio/client": "^1.6.0-beta.
|
15
|
-
"@gradio/
|
16
|
-
"@gradio/
|
17
|
-
"@gradio/upload": "^0.13.0-beta.
|
13
|
+
"@gradio/atoms": "^0.9.0-beta.4",
|
14
|
+
"@gradio/client": "^1.6.0-beta.4",
|
15
|
+
"@gradio/statustracker": "^0.8.0-beta.4",
|
16
|
+
"@gradio/icons": "^0.8.0-beta.3",
|
17
|
+
"@gradio/upload": "^0.13.0-beta.6",
|
18
18
|
"@gradio/utils": "^0.7.0-beta.2",
|
19
19
|
"@gradio/wasm": "^0.14.0-beta.3"
|
20
20
|
},
|
@@ -15,8 +15,9 @@
|
|
15
15
|
import ClearImage from "./ClearImage.svelte";
|
16
16
|
import { SelectSource } from "@gradio/atoms";
|
17
17
|
import Image from "./Image.svelte";
|
18
|
+
import type { Base64File } from "./types";
|
18
19
|
|
19
|
-
export let value: null | FileData;
|
20
|
+
export let value: null | FileData | Base64File = null;
|
20
21
|
export let label: string | undefined = undefined;
|
21
22
|
export let show_label: boolean;
|
22
23
|
|
@@ -59,6 +60,13 @@
|
|
59
60
|
img_blob: Blob | any,
|
60
61
|
event: "change" | "stream" | "upload"
|
61
62
|
): Promise<void> {
|
63
|
+
if (event === "stream") {
|
64
|
+
dispatch("stream", {
|
65
|
+
value: { url: img_blob } as Base64File,
|
66
|
+
is_value_data: true
|
67
|
+
});
|
68
|
+
return;
|
69
|
+
}
|
62
70
|
pending = true;
|
63
71
|
const f = await upload_input.load_files([
|
64
72
|
new File([img_blob], `image/${streaming ? "jpeg" : "png"}`)
|
@@ -68,8 +76,6 @@
|
|
68
76
|
value = f?.[0] || null;
|
69
77
|
await tick();
|
70
78
|
dispatch("change");
|
71
|
-
} else {
|
72
|
-
dispatch("stream", { value: f?.[0] || null, is_value_data: true });
|
73
79
|
}
|
74
80
|
pending = false;
|
75
81
|
}
|
package/shared/Webcam.svelte
CHANGED
@@ -17,6 +17,7 @@
|
|
17
17
|
get_video_stream,
|
18
18
|
set_available_devices
|
19
19
|
} from "./stream_utils";
|
20
|
+
import type { Base64File } from "./types";
|
20
21
|
|
21
22
|
let video_source: HTMLVideoElement;
|
22
23
|
let available_video_devices: MediaDeviceInfo[] = [];
|
@@ -53,10 +54,10 @@
|
|
53
54
|
export let include_audio: boolean;
|
54
55
|
export let i18n: I18nFormatter;
|
55
56
|
export let upload: Client["upload"];
|
56
|
-
export let value: FileData | null = null;
|
57
|
+
export let value: FileData | null | Base64File = null;
|
57
58
|
|
58
59
|
const dispatch = createEventDispatcher<{
|
59
|
-
stream:
|
60
|
+
stream: Blob | string;
|
60
61
|
capture: FileData | Blob | null;
|
61
62
|
error: string;
|
62
63
|
start_recording: undefined;
|
@@ -64,7 +65,16 @@
|
|
64
65
|
close_stream: undefined;
|
65
66
|
}>();
|
66
67
|
|
67
|
-
onMount(() =>
|
68
|
+
onMount(() => {
|
69
|
+
canvas = document.createElement("canvas");
|
70
|
+
if (streaming && mode === "image") {
|
71
|
+
window.setInterval(() => {
|
72
|
+
if (video_source && !pending) {
|
73
|
+
take_picture();
|
74
|
+
}
|
75
|
+
}, stream_every * 1000);
|
76
|
+
}
|
77
|
+
});
|
68
78
|
|
69
79
|
const handle_device_change = async (event: InputEvent): Promise<void> => {
|
70
80
|
const target = event.target as HTMLInputElement;
|
@@ -141,6 +151,11 @@
|
|
141
151
|
if (streaming && (!recording || stream_state === "waiting")) {
|
142
152
|
return;
|
143
153
|
}
|
154
|
+
if (streaming) {
|
155
|
+
const image_data = canvas.toDataURL("image/jpeg");
|
156
|
+
dispatch("stream", image_data);
|
157
|
+
return;
|
158
|
+
}
|
144
159
|
|
145
160
|
canvas.toBlob(
|
146
161
|
(blob) => {
|
@@ -226,14 +241,6 @@
|
|
226
241
|
}
|
227
242
|
}
|
228
243
|
|
229
|
-
if (streaming && mode === "image") {
|
230
|
-
window.setInterval(() => {
|
231
|
-
if (video_source && !pending) {
|
232
|
-
take_picture();
|
233
|
-
}
|
234
|
-
}, stream_every * 1000);
|
235
|
-
}
|
236
|
-
|
237
244
|
let options_open = false;
|
238
245
|
|
239
246
|
export function click_outside(node: Node, cb: any): any {
|
package/shared/types.ts
ADDED