@gradio/image 0.7.1 → 0.8.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,17 @@
1
1
  # @gradio/image
2
2
 
3
+ ## 0.8.0
4
+
5
+ ### Features
6
+
7
+ - [#7228](https://github.com/gradio-app/gradio/pull/7228) [`2e6672c`](https://github.com/gradio-app/gradio/commit/2e6672c815e39fd6af78353e66661100b9102cd4) - Allow start/pause of streaming image input. Only access the webcam while it's needed. Thanks [@freddyaboulton](https://github.com/freddyaboulton)!
8
+ - [#7309](https://github.com/gradio-app/gradio/pull/7309) [`200e251`](https://github.com/gradio-app/gradio/commit/200e2518e4d449aa82819a8d119e912bd1d95c15) - Add `gr.Image` interaction test + `gr.ImageEditor` interaction test improvement. Thanks [@hannahblair](https://github.com/hannahblair)!
9
+
10
+ ### Fixes
11
+
12
+ - [#7192](https://github.com/gradio-app/gradio/pull/7192) [`8dd6f4b`](https://github.com/gradio-app/gradio/commit/8dd6f4bc1901792f05cd59e86df7b1dbab692739) - Handle the case where examples is `null` for all components. Thanks [@abidlabs](https://github.com/abidlabs)!
13
+ - [#7325](https://github.com/gradio-app/gradio/pull/7325) [`733ca26`](https://github.com/gradio-app/gradio/commit/733ca266bb1ba9049ed7309b8f0614199682e173) - Ensure examples Images displays as expected. Thanks [@hannahblair](https://github.com/hannahblair)!
14
+
3
15
  ## 0.7.1
4
16
 
5
17
  ### Patch Changes
@@ -342,4 +354,4 @@ Thanks [@pngwn](https://github.com/pngwn)!
342
354
 
343
355
  ### Features
344
356
 
345
- - [#4979](https://github.com/gradio-app/gradio/pull/4979) [`44ac8ad0`](https://github.com/gradio-app/gradio/commit/44ac8ad08d82ea12c503dde5c78f999eb0452de2) - Allow setting sketch color default. Thanks [@aliabid94](https://github.com/aliabid94)!
357
+ - [#4979](https://github.com/gradio-app/gradio/pull/4979) [`44ac8ad0`](https://github.com/gradio-app/gradio/commit/44ac8ad08d82ea12c503dde5c78f999eb0452de2) - Allow setting sketch color default. Thanks [@aliabid94](https://github.com/aliabid94)!
package/Example.svelte CHANGED
@@ -13,8 +13,11 @@
13
13
  class:table={type === "table"}
14
14
  class:gallery={type === "gallery"}
15
15
  class:selected
16
+ class:border={value}
16
17
  >
17
- <Image src={samples_dir + value?.path} alt="" />
18
+ {#if value}
19
+ <Image src={samples_dir + value.path} alt="" />
20
+ {/if}
18
21
  </div>
19
22
 
20
23
  <style>
@@ -26,10 +29,12 @@
26
29
  .container.selected {
27
30
  border-color: var(--border-color-accent);
28
31
  }
32
+ .border.table {
33
+ border: 2px solid var(--border-color-primary);
34
+ }
29
35
 
30
36
  .container.table {
31
37
  margin: 0 auto;
32
- border: 2px solid var(--border-color-primary);
33
38
  border-radius: var(--radius-lg);
34
39
  overflow: hidden;
35
40
  width: var(--size-20);
@@ -38,8 +43,8 @@
38
43
  }
39
44
 
40
45
  .container.gallery {
41
- height: var(--size-20);
42
- max-height: var(--size-20);
46
+ width: var(--size-20);
47
+ max-width: var(--size-20);
43
48
  object-fit: cover;
44
49
  }
45
50
  </style>
@@ -1,10 +1,22 @@
1
- <script lang="ts">
2
- import { Meta, Template, Story } from "@storybook/addon-svelte-csf";
1
+ <script context="module">
2
+ import { Template, Story } from "@storybook/addon-svelte-csf";
3
3
  import StaticImage from "./Index.svelte";
4
4
  import { userEvent, within } from "@storybook/testing-library";
5
- </script>
5
+ import { allModes } from "../storybook/modes";
6
6
 
7
- <Meta title="Components/Image" component={Image} />
7
+ export const meta = {
8
+ title: "Components/Image",
9
+ component: StaticImage,
10
+ parameters: {
11
+ chromatic: {
12
+ modes: {
13
+ desktop: allModes["desktop"],
14
+ mobile: allModes["mobile"]
15
+ }
16
+ }
17
+ }
18
+ };
19
+ </script>
8
20
 
9
21
  <Template let:args>
10
22
  <div
@@ -60,8 +72,7 @@
60
72
  const webcamButton = await canvas.findByLabelText("Capture from camera");
61
73
  userEvent.click(webcamButton);
62
74
 
63
- userEvent.click(await canvas.findByTitle("select video source"));
64
- userEvent.click(await canvas.findByLabelText("select source"));
75
+ userEvent.click(await canvas.findByTitle("grant webcam access"));
65
76
  userEvent.click(await canvas.findByLabelText("Upload file"));
66
77
  userEvent.click(await canvas.findByLabelText("Paste from clipboard"));
67
78
  }}
@@ -0,0 +1,29 @@
1
+ <script>
2
+ import { Meta, Template, Story } from "@storybook/addon-svelte-csf";
3
+ import Image from "./Example.svelte";
4
+ </script>
5
+
6
+ <Meta title="Components/Image/Example" component={Image} />
7
+
8
+ <Template let:args>
9
+ <Image {...args} />
10
+ </Template>
11
+
12
+ <Story
13
+ name="Image file"
14
+ args={{
15
+ samples_dir: "",
16
+ value: {
17
+ path: "https://gradio-builds.s3.amazonaws.com/demo-files/ghepardo-primo-piano.jpg",
18
+ url: "https://gradio-builds.s3.amazonaws.com/demo-files/ghepardo-primo-piano.jpg",
19
+ orig_name: "cheetah.jpg"
20
+ }
21
+ }}
22
+ />
23
+
24
+ <Story
25
+ name="Null"
26
+ args={{
27
+ value: null
28
+ }}
29
+ />
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gradio/image",
3
- "version": "0.7.1",
3
+ "version": "0.8.0",
4
4
  "description": "Gradio UI packages",
5
5
  "type": "module",
6
6
  "author": "",
@@ -10,13 +10,13 @@
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.5.0",
13
+ "@gradio/atoms": "^0.5.1",
14
+ "@gradio/client": "^0.11.0",
14
15
  "@gradio/icons": "^0.3.2",
15
- "@gradio/client": "^0.10.1",
16
- "@gradio/statustracker": "^0.4.4",
17
- "@gradio/upload": "^0.7.0",
18
- "@gradio/utils": "^0.2.1",
19
- "@gradio/wasm": "^0.5.1"
16
+ "@gradio/statustracker": "^0.4.5",
17
+ "@gradio/wasm": "^0.6.0",
18
+ "@gradio/upload": "^0.7.1",
19
+ "@gradio/utils": "^0.2.2"
20
20
  },
21
21
  "main_changeset": true,
22
22
  "main": "./Index.svelte",
@@ -35,3 +35,9 @@
35
35
 
36
36
  <!-- svelte-ignore a11y-missing-attribute -->
37
37
  <img src={resolved_src} {...$$restProps} />
38
+
39
+ <style>
40
+ img {
41
+ object-fit: cover;
42
+ }
43
+ </style>
@@ -1,9 +1,17 @@
1
1
  <script lang="ts">
2
2
  import { createEventDispatcher, onMount } from "svelte";
3
- import { Camera, Circle, Square, DropdownArrow } from "@gradio/icons";
3
+ import {
4
+ Camera,
5
+ Circle,
6
+ Square,
7
+ DropdownArrow,
8
+ Webcam as WebcamIcon
9
+ } from "@gradio/icons";
4
10
  import type { I18nFormatter } from "@gradio/utils";
5
11
  import type { FileData } from "@gradio/client";
6
12
  import { prepare_files, upload } from "@gradio/client";
13
+ import WebcamPermissions from "./WebcamPermissions.svelte";
14
+ import { fade } from "svelte/transition";
7
15
 
8
16
  let video_source: HTMLVideoElement;
9
17
  let canvas: HTMLCanvasElement;
@@ -42,6 +50,7 @@
42
50
  video_source.srcObject = stream;
43
51
  video_source.muted = true;
44
52
  video_source.play();
53
+ webcam_accessed = true;
45
54
  } catch (err) {
46
55
  if (err instanceof DOMException && err.name == "NotAllowedError") {
47
56
  dispatch("error", i18n("image.allow_webcam_access"));
@@ -53,8 +62,11 @@
53
62
 
54
63
  function take_picture(): void {
55
64
  var context = canvas.getContext("2d")!;
56
-
57
- if (video_source.videoWidth && video_source.videoHeight) {
65
+ if (
66
+ (!streaming || (streaming && recording)) &&
67
+ video_source.videoWidth &&
68
+ video_source.videoHeight
69
+ ) {
58
70
  canvas.width = video_source.videoWidth;
59
71
  canvas.height = video_source.videoHeight;
60
72
  context.drawImage(
@@ -131,7 +143,23 @@
131
143
  recording = !recording;
132
144
  }
133
145
 
134
- access_webcam();
146
+ let webcam_accessed = false;
147
+
148
+ function record_video_or_photo(): void {
149
+ if (mode === "image" && streaming) {
150
+ recording = !recording;
151
+ }
152
+ if (mode === "image") {
153
+ take_picture();
154
+ } else {
155
+ take_recording();
156
+ }
157
+ if (!recording && stream) {
158
+ stream.getTracks().forEach((track) => track.stop());
159
+ video_source.srcObject = null;
160
+ webcam_accessed = false;
161
+ }
162
+ }
135
163
 
136
164
  if (streaming && mode === "image") {
137
165
  window.setInterval(() => {
@@ -185,14 +213,22 @@
185
213
  <div class="wrap">
186
214
  <!-- svelte-ignore a11y-media-has-caption -->
187
215
  <!-- need to suppress for video streaming https://github.com/sveltejs/svelte/issues/5967 -->
188
- <video bind:this={video_source} class:flip={mirror_webcam} />
189
- {#if !streaming}
216
+ <video
217
+ bind:this={video_source}
218
+ class:flip={mirror_webcam}
219
+ class:hide={!webcam_accessed}
220
+ />
221
+ {#if !webcam_accessed}
222
+ <div in:fade={{ delay: 100, duration: 200 }} title="grant webcam access">
223
+ <WebcamPermissions on:click={async () => access_webcam()} />
224
+ </div>
225
+ {:else}
190
226
  <div class="button-wrap">
191
227
  <button
192
- on:click={mode === "image" ? take_picture : take_recording}
228
+ on:click={record_video_or_photo}
193
229
  aria-label={mode === "image" ? "capture photo" : "start recording"}
194
230
  >
195
- {#if mode === "video"}
231
+ {#if mode === "video" || streaming}
196
232
  {#if recording}
197
233
  <div class="icon red" title="stop recording">
198
234
  <Square />
@@ -208,15 +244,13 @@
208
244
  </div>
209
245
  {/if}
210
246
  </button>
211
-
212
247
  {#if !recording}
213
248
  <button
249
+ class="icon"
214
250
  on:click={select_source}
215
- aria-label={mode === "image" ? "capture photo" : "start recording"}
251
+ aria-label="select input source"
216
252
  >
217
- <div class="icon" title="select video source">
218
- <DropdownArrow />
219
- </div>
253
+ <DropdownArrow />
220
254
  </button>
221
255
  {/if}
222
256
  </div>
@@ -253,6 +287,10 @@
253
287
  height: var(--size-full);
254
288
  }
255
289
 
290
+ .hide {
291
+ display: none;
292
+ }
293
+
256
294
  video {
257
295
  width: var(--size-full);
258
296
  height: var(--size-full);
@@ -353,4 +391,10 @@
353
391
  height: var(--size-5);
354
392
  opacity: 0.8;
355
393
  }
394
+
395
+ @media (--screen-md) {
396
+ .wrap {
397
+ font-size: var(--text-lg);
398
+ }
399
+ }
356
400
  </style>
@@ -0,0 +1,46 @@
1
+ <script lang="ts">
2
+ import { Webcam } from "@gradio/icons";
3
+ import { createEventDispatcher } from "svelte";
4
+
5
+ const dispatch = createEventDispatcher<{
6
+ click: undefined;
7
+ }>();
8
+ </script>
9
+
10
+ <button style:height="100%" on:click={() => dispatch("click")}>
11
+ <div class="wrap">
12
+ <span class="icon-wrap">
13
+ <Webcam />
14
+ </span>
15
+ {"Click to Access Webcam"}
16
+ </div>
17
+ </button>
18
+
19
+ <style>
20
+ button {
21
+ cursor: pointer;
22
+ width: var(--size-full);
23
+ }
24
+
25
+ .wrap {
26
+ display: flex;
27
+ flex-direction: column;
28
+ justify-content: center;
29
+ align-items: center;
30
+ min-height: var(--size-60);
31
+ color: var(--block-label-text-color);
32
+ height: 100%;
33
+ padding-top: var(--size-3);
34
+ }
35
+
36
+ .icon-wrap {
37
+ width: 30px;
38
+ margin-bottom: var(--spacing-lg);
39
+ }
40
+
41
+ @media (--screen-md) {
42
+ .wrap {
43
+ font-size: var(--text-lg);
44
+ }
45
+ }
46
+ </style>