@gradio/image 0.16.0-beta.5 → 0.16.0-beta.7

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,31 @@
1
1
  # @gradio/image
2
2
 
3
+ ## 0.16.0-beta.7
4
+
5
+ ### Features
6
+
7
+ - [#9582](https://github.com/gradio-app/gradio/pull/9582) [`43a7f42`](https://github.com/gradio-app/gradio/commit/43a7f420d8ac34c7f7fa71d6e630a4c8618d3780) - Chatbot autoscroll. Thanks @whitphx!
8
+
9
+ ### Dependency updates
10
+
11
+ - @gradio/upload@0.13.0-beta.7
12
+ - @gradio/statustracker@0.8.0-beta.5
13
+ - @gradio/icons@0.8.0-beta.4
14
+ - @gradio/atoms@0.9.0-beta.5
15
+
16
+ ## 0.16.0-beta.6
17
+
18
+ ### Features
19
+
20
+ - [#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!
21
+
22
+ ### Dependency updates
23
+
24
+ - @gradio/statustracker@0.8.0-beta.4
25
+ - @gradio/atoms@0.9.0-beta.4
26
+ - @gradio/client@1.6.0-beta.4
27
+ - @gradio/upload@0.13.0-beta.6
28
+
3
29
  ## 0.16.0-beta.5
4
30
 
5
31
  ### Dependency updates
@@ -1,6 +1,4 @@
1
- <script>import { createEventDispatcher } from "svelte";
2
- const dispatch = createEventDispatcher();
3
- import { resolve_wasm_src } from "@gradio/wasm/svelte";
1
+ <script>import { resolve_wasm_src } from "@gradio/wasm/svelte";
4
2
  export let src = void 0;
5
3
  let resolved_src;
6
4
  let latest_src;
@@ -17,7 +15,7 @@ $: {
17
15
  </script>
18
16
 
19
17
  <!-- svelte-ignore a11y-missing-attribute -->
20
- <img src={resolved_src} {...$$restProps} on:load={() => dispatch("load")} />
18
+ <img src={resolved_src} {...$$restProps} on:load />
21
19
 
22
20
  <style>
23
21
  img {
@@ -233,7 +233,7 @@ declare const __propDef: {
233
233
  "data-testid"?: string | undefined;
234
234
  };
235
235
  events: {
236
- load?: CustomEvent<void | undefined> | undefined;
236
+ load: Event;
237
237
  } & {
238
238
  [evt: string]: CustomEvent<any>;
239
239
  };
@@ -16,7 +16,7 @@ declare const __propDef: {
16
16
  events: {
17
17
  share: CustomEvent<import("@gradio/utils").ShareData>;
18
18
  error: CustomEvent<string>;
19
- load: CustomEvent<void | undefined> | undefined;
19
+ load: Event;
20
20
  change: CustomEvent<string>;
21
21
  select: CustomEvent<SelectData>;
22
22
  } & {
@@ -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: null | FileData;
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(() => canvas = document.createElement("canvas"));
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<undefined>;
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,4 @@
1
+ export interface Base64File {
2
+ url: string;
3
+ alt_text: string;
4
+ }
@@ -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.5",
3
+ "version": "0.16.0-beta.7",
4
4
  "description": "Gradio UI packages",
5
5
  "type": "module",
6
6
  "author": "",
@@ -10,16 +10,16 @@
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.3",
14
- "@gradio/icons": "^0.8.0-beta.3",
15
- "@gradio/client": "^1.6.0-beta.3",
16
- "@gradio/upload": "^0.13.0-beta.5",
17
- "@gradio/statustracker": "^0.8.0-beta.3",
13
+ "@gradio/atoms": "^0.9.0-beta.5",
14
+ "@gradio/icons": "^0.8.0-beta.4",
15
+ "@gradio/statustracker": "^0.8.0-beta.5",
16
+ "@gradio/client": "^1.6.0-beta.4",
17
+ "@gradio/upload": "^0.13.0-beta.7",
18
18
  "@gradio/utils": "^0.7.0-beta.2",
19
19
  "@gradio/wasm": "^0.14.0-beta.3"
20
20
  },
21
21
  "devDependencies": {
22
- "@gradio/preview": "^0.11.2-beta.0"
22
+ "@gradio/preview": "^0.12.0-beta.1"
23
23
  },
24
24
  "main_changeset": true,
25
25
  "main": "./Index.svelte",
@@ -1,8 +1,6 @@
1
1
  <script lang="ts">
2
2
  import type { HTMLImgAttributes } from "svelte/elements";
3
- import { createEventDispatcher } from "svelte";
4
3
 
5
- const dispatch = createEventDispatcher<{ load?: void }>();
6
4
  interface Props extends HTMLImgAttributes {
7
5
  "data-testid"?: string;
8
6
  }
@@ -37,7 +35,7 @@
37
35
  </script>
38
36
 
39
37
  <!-- svelte-ignore a11y-missing-attribute -->
40
- <img src={resolved_src} {...$$restProps} on:load={() => dispatch("load")} />
38
+ <img src={resolved_src} {...$$restProps} on:load />
41
39
 
42
40
  <style>
43
41
  img {
@@ -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
  }
@@ -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: undefined;
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(() => (canvas = document.createElement("canvas")));
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 {
@@ -0,0 +1,4 @@
1
+ export interface Base64File {
2
+ url: string;
3
+ alt_text: string;
4
+ }