@gradio/gallery 0.4.0-beta.5

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 ADDED
@@ -0,0 +1,126 @@
1
+ # @gradio/gallery
2
+
3
+ ## 0.4.0-beta.5
4
+
5
+ ### Features
6
+
7
+ - [#5648](https://github.com/gradio-app/gradio/pull/5648) [`c573e2339`](https://github.com/gradio-app/gradio/commit/c573e2339b86c85b378dc349de5e9223a3c3b04a) - Publish all components to npm. Thanks [@freddyaboulton](https://github.com/freddyaboulton)!
8
+
9
+ ## 0.4.0-beta.4
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies [[`0b4fd5b6d`](https://github.com/gradio-app/gradio/commit/0b4fd5b6db96fc95a155e5e935e17e1ab11d1161)]:
14
+ - @gradio/utils@0.2.0-beta.3
15
+ - @gradio/atoms@0.2.0-beta.3
16
+ - @gradio/image@0.3.0-beta.4
17
+ - @gradio/statustracker@0.3.0-beta.4
18
+ - @gradio/upload@0.3.0-beta.3
19
+
20
+ ## 0.4.0-beta.3
21
+
22
+ ### Patch Changes
23
+
24
+ - Updated dependencies [[`14fc612d8`](https://github.com/gradio-app/gradio/commit/14fc612d84bf6b1408eccd3a40fab41f25477571)]:
25
+ - @gradio/utils@0.2.0-beta.2
26
+ - @gradio/atoms@0.2.0-beta.2
27
+ - @gradio/image@0.3.0-beta.3
28
+ - @gradio/statustracker@0.3.0-beta.3
29
+ - @gradio/upload@0.3.0-beta.2
30
+
31
+ ## 0.4.0-beta.2
32
+
33
+ ### Features
34
+
35
+ - [#5620](https://github.com/gradio-app/gradio/pull/5620) [`c4c25ecdf`](https://github.com/gradio-app/gradio/commit/c4c25ecdf8c2fab5e3c41b519564e3b6a9ebfce3) - fix build and broken imports. Thanks [@pngwn](https://github.com/pngwn)!
36
+
37
+ ## 0.4.0-beta.1
38
+
39
+ ### Patch Changes
40
+
41
+ - Updated dependencies []:
42
+ - @gradio/utils@0.2.0-beta.1
43
+ - @gradio/atoms@0.2.0-beta.1
44
+ - @gradio/image@0.3.0-beta.1
45
+ - @gradio/statustracker@0.3.0-beta.1
46
+ - @gradio/upload@0.3.0-beta.1
47
+
48
+ ## 0.4.0-beta.0
49
+
50
+ ### Features
51
+
52
+ - [#5507](https://github.com/gradio-app/gradio/pull/5507) [`1385dc688`](https://github.com/gradio-app/gradio/commit/1385dc6881f2d8ae7a41106ec21d33e2ef04d6a9) - Custom components. Thanks [@pngwn](https://github.com/pngwn)!
53
+
54
+ ## 0.3.4
55
+
56
+ ### Patch Changes
57
+
58
+ - Updated dependencies [[`e0d61b8ba`](https://github.com/gradio-app/gradio/commit/e0d61b8baa0f6293f53b9bdb1647d42f9ae2583a)]:
59
+ - @gradio/image@0.2.4
60
+
61
+ ## 0.3.3
62
+
63
+ ### Fixes
64
+
65
+ - [#5528](https://github.com/gradio-app/gradio/pull/5528) [`dc86e4a7`](https://github.com/gradio-app/gradio/commit/dc86e4a7e1c40b910c74558e6f88fddf9b3292bc) - Lazy load all images. Thanks [@aliabid94](https://github.com/aliabid94)!
66
+
67
+ ## 0.3.2
68
+
69
+ ### Patch Changes
70
+
71
+ - Updated dependencies [[`afac0006`](https://github.com/gradio-app/gradio/commit/afac0006337ce2840cf497cd65691f2f60ee5912)]:
72
+ - @gradio/statustracker@0.2.0
73
+ - @gradio/image@0.2.2
74
+ - @gradio/utils@0.1.1
75
+ - @gradio/atoms@0.1.2
76
+ - @gradio/upload@0.2.1
77
+
78
+ ## 0.3.1
79
+
80
+ ### Patch Changes
81
+
82
+ - Updated dependencies [[`abf1c57d`](https://github.com/gradio-app/gradio/commit/abf1c57d7d85de0df233ee3b38aeb38b638477db), [`79d8f9d8`](https://github.com/gradio-app/gradio/commit/79d8f9d891901683c5a1b7486efb44eab2478c96)]:
83
+ - @gradio/icons@0.1.0
84
+ - @gradio/utils@0.1.0
85
+ - @gradio/upload@0.2.0
86
+ - @gradio/atoms@0.1.1
87
+ - @gradio/image@0.2.1
88
+ - @gradio/statustracker@0.1.1
89
+
90
+ ## 0.3.0
91
+
92
+ ### Highlights
93
+
94
+ #### Improve startup performance and markdown support ([#5279](https://github.com/gradio-app/gradio/pull/5279) [`fe057300`](https://github.com/gradio-app/gradio/commit/fe057300f0672c62dab9d9b4501054ac5d45a4ec))
95
+
96
+ ##### Improved markdown support
97
+
98
+ We now have better support for markdown in `gr.Markdown` and `gr.Dataframe`. Including syntax highlighting and Github Flavoured Markdown. We also have more consistent markdown behaviour and styling.
99
+
100
+ ##### Various performance improvements
101
+
102
+ These improvements will be particularly beneficial to large applications.
103
+
104
+ - Rather than attaching events manually, they are now delegated, leading to a significant performance improvement and addressing a performance regression introduced in a recent version of Gradio. App startup for large applications is now around twice as fast.
105
+ - Optimised the mounting of individual components, leading to a modest performance improvement during startup (~30%).
106
+ - Corrected an issue that was causing markdown to re-render infinitely.
107
+ - Ensured that the `gr.3DModel` does re-render prematurely.
108
+
109
+ Thanks [@pngwn](https://github.com/pngwn)!
110
+
111
+ ### Features
112
+
113
+ - [#5215](https://github.com/gradio-app/gradio/pull/5215) [`fbdad78a`](https://github.com/gradio-app/gradio/commit/fbdad78af4c47454cbb570f88cc14bf4479bbceb) - Lazy load interactive or static variants of a component individually, rather than loading both variants regardless. This change will improve performance for many applications. Thanks [@pngwn](https://github.com/pngwn)!
114
+ - [#5216](https://github.com/gradio-app/gradio/pull/5216) [`4b58ea6d`](https://github.com/gradio-app/gradio/commit/4b58ea6d98e7a43b3f30d8a4cb6f379bc2eca6a8) - Update i18n tokens and locale files. Thanks [@hannahblair](https://github.com/hannahblair)!
115
+
116
+ ## 0.2.0
117
+
118
+ ### Features
119
+
120
+ - [#5025](https://github.com/gradio-app/gradio/pull/5025) [`6693660a`](https://github.com/gradio-app/gradio/commit/6693660a790996f8f481feaf22a8c49130d52d89) - Add download button to selected images in `Gallery`. Thanks [@hannahblair](https://github.com/hannahblair)!
121
+
122
+ ## 0.1.0
123
+
124
+ ### Features
125
+
126
+ - [#4995](https://github.com/gradio-app/gradio/pull/4995) [`3f8c210b`](https://github.com/gradio-app/gradio/commit/3f8c210b01ef1ceaaf8ee73be4bf246b5b745bbf) - Implement left and right click in `Gallery` component and show implicit images in `Gallery` grid. Thanks [@hannahblair](https://github.com/hannahblair)!
@@ -0,0 +1,209 @@
1
+ <script>
2
+ import { Meta, Template, Story } from "@storybook/addon-svelte-csf";
3
+ import Gallery from "./static/";
4
+ </script>
5
+
6
+ <Meta
7
+ title="Components/Gallery"
8
+ component={Gallery}
9
+ argTypes={{
10
+ label: {
11
+ control: "text",
12
+ description: "The gallery label",
13
+ name: "label",
14
+ value: "Gradio Button"
15
+ },
16
+ show_label: {
17
+ options: [true, false],
18
+ description: "Whether to show the label",
19
+ control: { type: "boolean" },
20
+ defaultValue: true
21
+ },
22
+ grid_cols: {
23
+ options: [1, 2, 3, 4],
24
+ description: "The number of columns to show in grid",
25
+ control: { type: "select" },
26
+ defaultValue: 2
27
+ },
28
+ grid_rows: {
29
+ options: [1, 2, 3, 4],
30
+ description: "The number of rows to show in grid",
31
+ control: { type: "select" },
32
+ defaultValue: 2
33
+ },
34
+ height: {
35
+ options: ["auto", 500, 600],
36
+ description: "The height of the grid",
37
+ control: { type: "select" },
38
+ defaultValue: "auto"
39
+ },
40
+ preview: {
41
+ options: [true, false],
42
+ description: "Whether to start the gallery in preview mode",
43
+ control: { type: "boolean" },
44
+ defaultValue: true
45
+ },
46
+ allow_preview: {
47
+ options: [true, false],
48
+ description: "Whether to allow a preview mode in the gallery",
49
+ control: { type: "boolean" },
50
+ defaultValue: true
51
+ },
52
+ object_fit: {
53
+ options: ["contain", "cover", "fill", "none", "scale-down"],
54
+ description: "How to display each indivial image in the grid",
55
+ control: { type: "select" },
56
+ defaultValue: "contain"
57
+ },
58
+ show_share_button: {
59
+ options: [true, false],
60
+ description: "Whether to show the share button in the gallery",
61
+ control: { type: "boolean" },
62
+ defaultValue: false
63
+ }
64
+ }}
65
+ />
66
+
67
+ <Template let:args>
68
+ <Gallery
69
+ value={[
70
+ [
71
+ "https://gradio-builds.s3.amazonaws.com/demo-files/cheetah_running.avif",
72
+ "A fast cheetah"
73
+ ],
74
+ "https://gradio-builds.s3.amazonaws.com/demo-files/cheetah-002.jpg",
75
+ "https://gradio-builds.s3.amazonaws.com/demo-files/cheetah-003.jpg",
76
+ "https://gradio-builds.s3.amazonaws.com/demo-files/cheetah3.webp",
77
+ "https://gradio-builds.s3.amazonaws.com/demo-files/ghepardo-primo-piano.jpg",
78
+ "https://gradio-builds.s3.amazonaws.com/demo-files/main-qimg-0bbf31c18a22178cb7a8dd53640a3d05-lq.jpeg",
79
+ "https://gradio-builds.s3.amazonaws.com/demo-files/TheCheethcat.jpg"
80
+ ]}
81
+ {...args}
82
+ />
83
+ </Template>
84
+
85
+ <Story
86
+ name="Gallery with label"
87
+ args={{ label: "My Cheetah Gallery", show_label: true }}
88
+ />
89
+ <Story
90
+ name="Gallery without label"
91
+ args={{ label: "My Cheetah Gallery", show_label: false }}
92
+ />
93
+ <Story
94
+ name="Gallery with grid_rows=3 and grid_cols=3"
95
+ args={{
96
+ label: "My Cheetah Gallery",
97
+ show_label: true,
98
+ grid_rows: 3,
99
+ grid_cols: 3
100
+ }}
101
+ />
102
+ <Story
103
+ name="Gallery with grid_cols=4"
104
+ args={{
105
+ label: "My Cheetah Gallery",
106
+ show_label: true,
107
+ grid_cols: 4
108
+ }}
109
+ />
110
+ <Story
111
+ name="Gallery with height=600"
112
+ args={{
113
+ label: "My Cheetah Gallery",
114
+ height: 600
115
+ }}
116
+ />
117
+ <Story
118
+ name="Gallery with allow_preview=false"
119
+ args={{
120
+ label: "My Cheetah Gallery",
121
+ show_label: true,
122
+ allow_preview: false
123
+ }}
124
+ />
125
+ <Story
126
+ name="Gallery with preview"
127
+ args={{
128
+ label: "My Cheetah Gallery",
129
+ show_label: true,
130
+ preview: true
131
+ }}
132
+ />
133
+ <Story
134
+ name="Gallery with object_fit=scale-down"
135
+ args={{
136
+ label: "My Cheetah Gallery",
137
+ show_label: true,
138
+ object_fit: "scale-down"
139
+ }}
140
+ />
141
+ <Story
142
+ name="Gallery with object_fit=contain"
143
+ args={{
144
+ label: "My Cheetah Gallery",
145
+ show_label: true,
146
+ object_fit: "contain"
147
+ }}
148
+ />
149
+ <Story
150
+ name="Gallery with object_fit=cover"
151
+ args={{
152
+ label: "My Cheetah Gallery",
153
+ show_label: true,
154
+ object_fit: "cover"
155
+ }}
156
+ />
157
+ <Story
158
+ name="Gallery with object_fit=none"
159
+ args={{
160
+ label: "My Cheetah Gallery",
161
+ show_label: true,
162
+ object_fit: "none"
163
+ }}
164
+ />
165
+ <Story
166
+ name="Gallery with object_fit=fill"
167
+ args={{
168
+ label: "My Cheetah Gallery",
169
+ show_label: true,
170
+ object_fit: "fill"
171
+ }}
172
+ />
173
+ <Story
174
+ name="Gallery with share button"
175
+ args={{
176
+ label: "My Cheetah Gallery",
177
+ show_label: true,
178
+ show_share_button: true
179
+ }}
180
+ />
181
+
182
+ <Story
183
+ name="Gallery with overflow of images"
184
+ args={{
185
+ label: "My Cheetah Gallery",
186
+ show_label: true,
187
+ grid_rows: 2,
188
+ grid_cols: 2,
189
+ height: 400,
190
+ value: [
191
+ "https://gradio-builds.s3.amazonaws.com/demo-files/cheetah-002.jpg",
192
+ "https://gradio-builds.s3.amazonaws.com/demo-files/cheetah-003.jpg",
193
+ "https://gradio-builds.s3.amazonaws.com/demo-files/ghepardo-primo-piano.jpg",
194
+ "https://gradio-builds.s3.amazonaws.com/demo-files/ghepardo-primo-piano.jpg",
195
+ "https://gradio-builds.s3.amazonaws.com/demo-files/cheetah-002.jpg"
196
+ ]
197
+ }}
198
+ />
199
+
200
+ <Story
201
+ name="Gallery with download button"
202
+ args={{
203
+ label: "My Cheetah Gallery",
204
+ grid_rows: 2,
205
+ height: 400,
206
+ show_download_button: true,
207
+ value: ["https://gradio-builds.s3.amazonaws.com/demo-files/cheetah-002.jpg"]
208
+ }}
209
+ />
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # `@gradio/button`
2
+
3
+ ```html
4
+ <script>
5
+ import { Button } from "@gradio/button";
6
+ </script>
7
+
8
+ <button type="primary|secondary" href="string" on:click="{e.detail === href}">
9
+ content
10
+ </button>
11
+ ```
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@gradio/gallery",
3
+ "version": "0.4.0-beta.5",
4
+ "description": "Gradio UI packages",
5
+ "type": "module",
6
+ "main": "./static/index.ts",
7
+ "author": "",
8
+ "license": "ISC",
9
+ "private": false,
10
+ "dependencies": {
11
+ "@gradio/atoms": "^0.2.0-beta.3",
12
+ "@gradio/icons": "^0.2.0-beta.0",
13
+ "@gradio/image": "^0.3.0-beta.5",
14
+ "@gradio/statustracker": "^0.3.0-beta.5",
15
+ "@gradio/upload": "^0.3.0-beta.3",
16
+ "@gradio/utils": "^0.2.0-beta.3"
17
+ },
18
+ "main_changeset": true,
19
+ "exports": {
20
+ ".": "./static/index.ts",
21
+ "./package.json": "./package.json",
22
+ "./interactive": "./interactive/index.ts",
23
+ "./static": "./static/index.ts",
24
+ "./example": "./example/index.ts"
25
+ }
26
+ }
@@ -0,0 +1,450 @@
1
+ <script lang="ts">
2
+ import { BlockLabel, Empty, ShareButton } from "@gradio/atoms";
3
+ import { ModifyUpload } from "@gradio/upload";
4
+ import type { SelectData } from "@gradio/utils";
5
+
6
+ import { createEventDispatcher } from "svelte";
7
+ import { tick } from "svelte";
8
+
9
+ import { Download, Image } from "@gradio/icons";
10
+ import type { FileData } from "@gradio/upload";
11
+ import { normalise_file } from "@gradio/upload";
12
+ import { format_gallery_for_sharing } from "./utils";
13
+ import { IconButton } from "@gradio/atoms";
14
+ import type { I18nFormatter } from "@gradio/utils";
15
+
16
+ export let show_label = true;
17
+ export let label: string;
18
+ export let root = "";
19
+ export let root_url: null | string = null;
20
+ export let value: { image: FileData; caption: string | null }[] | null = null;
21
+ export let grid_cols: number | number[] | undefined = [2];
22
+ export let grid_rows: number | number[] | undefined = undefined;
23
+ export let height: number | "auto" = "auto";
24
+ export let preview: boolean;
25
+ export let allow_preview = true;
26
+ export let object_fit: "contain" | "cover" | "fill" | "none" | "scale-down" =
27
+ "cover";
28
+ export let show_share_button = false;
29
+ export let show_download_button = false;
30
+ export let i18n: I18nFormatter;
31
+
32
+ const dispatch = createEventDispatcher<{
33
+ select: SelectData;
34
+ }>();
35
+
36
+ // tracks whether the value of the gallery was reset
37
+ let was_reset = true;
38
+
39
+ $: was_reset = value == null || value.length == 0 ? true : was_reset;
40
+
41
+ let _value: { image: FileData; caption: string | null }[] | null = null;
42
+ $: _value =
43
+ value === null
44
+ ? null
45
+ : value.map((data) => ({
46
+ image: normalise_file(data.image, root, root_url) as FileData,
47
+ caption: data.caption
48
+ }));
49
+
50
+ let prevValue: { image: FileData; caption: string | null }[] | null | null =
51
+ value;
52
+ let selected_image = preview && value?.length ? 0 : null;
53
+ let old_selected_image: number | null = selected_image;
54
+
55
+ $: if (prevValue !== value) {
56
+ // When value is falsy (clear button or first load),
57
+ // preview determines the selected image
58
+ if (was_reset) {
59
+ selected_image = preview && value?.length ? 0 : null;
60
+ was_reset = false;
61
+ // Otherwise we keep the selected_image the same if the
62
+ // gallery has at least as many elements as it did before
63
+ } else {
64
+ selected_image =
65
+ selected_image !== null &&
66
+ value !== null &&
67
+ selected_image < value.length
68
+ ? selected_image
69
+ : null;
70
+ }
71
+ prevValue = value;
72
+ }
73
+
74
+ $: previous =
75
+ ((selected_image ?? 0) + (_value?.length ?? 0) - 1) % (_value?.length ?? 0);
76
+ $: next = ((selected_image ?? 0) + 1) % (_value?.length ?? 0);
77
+
78
+ function handle_preview_click(event: MouseEvent): void {
79
+ const element = event.target as HTMLElement;
80
+ const x = event.clientX;
81
+ const width = element.offsetWidth;
82
+ const centerX = width / 2;
83
+
84
+ if (x < centerX) {
85
+ selected_image = previous;
86
+ } else {
87
+ selected_image = next;
88
+ }
89
+ }
90
+
91
+ function on_keydown(e: KeyboardEvent): void {
92
+ switch (e.code) {
93
+ case "Escape":
94
+ e.preventDefault();
95
+ selected_image = null;
96
+ break;
97
+ case "ArrowLeft":
98
+ e.preventDefault();
99
+ selected_image = previous;
100
+ break;
101
+ case "ArrowRight":
102
+ e.preventDefault();
103
+ selected_image = next;
104
+ break;
105
+ default:
106
+ break;
107
+ }
108
+ }
109
+
110
+ function isFileData(obj: any): obj is FileData {
111
+ return typeof obj === "object" && obj !== null && "data" in obj;
112
+ }
113
+
114
+ function getHrefValue(selected: any): string {
115
+ if (isFileData(selected)) {
116
+ return selected.data;
117
+ } else if (typeof selected === "string") {
118
+ return selected;
119
+ }
120
+ return "";
121
+ }
122
+
123
+ $: {
124
+ if (selected_image !== old_selected_image) {
125
+ old_selected_image = selected_image;
126
+ if (selected_image !== null) {
127
+ dispatch("select", {
128
+ index: selected_image,
129
+ value: _value?.[selected_image].caption
130
+ });
131
+ }
132
+ }
133
+ }
134
+
135
+ $: if (allow_preview) {
136
+ scroll_to_img(selected_image);
137
+ }
138
+
139
+ let el: HTMLButtonElement[] = [];
140
+ let container_element: HTMLDivElement;
141
+
142
+ async function scroll_to_img(index: number | null): Promise<void> {
143
+ if (typeof index !== "number") return;
144
+ await tick();
145
+
146
+ el[index].focus();
147
+
148
+ const { left: container_left, width: container_width } =
149
+ container_element.getBoundingClientRect();
150
+ const { left, width } = el[index].getBoundingClientRect();
151
+
152
+ const relative_left = left - container_left;
153
+
154
+ const pos =
155
+ relative_left +
156
+ width / 2 -
157
+ container_width / 2 +
158
+ container_element.scrollLeft;
159
+
160
+ container_element?.scrollTo({
161
+ left: pos < 0 ? 0 : pos,
162
+ behavior: "smooth"
163
+ });
164
+ }
165
+
166
+ let client_height = 0;
167
+ let window_height = 0;
168
+ </script>
169
+
170
+ <svelte:window bind:innerHeight={window_height} />
171
+
172
+ {#if show_label}
173
+ <BlockLabel {show_label} Icon={Image} label={label || "Gallery"} />
174
+ {/if}
175
+ {#if value === null || _value === null || _value.length === 0}
176
+ <Empty unpadded_box={true} size="large"><Image /></Empty>
177
+ {:else}
178
+ {#if selected_image !== null && allow_preview}
179
+ <!-- svelte-ignore a11y-no-static-element-interactions -->
180
+ <div on:keydown={on_keydown} class="preview">
181
+ <div class="icon-buttons">
182
+ {#if show_download_button}
183
+ <a
184
+ href={getHrefValue(value[selected_image])}
185
+ target={window.__is_colab__ ? "_blank" : null}
186
+ download="image"
187
+ >
188
+ <IconButton Icon={Download} label={i18n("common.download")} />
189
+ </a>
190
+ {/if}
191
+
192
+ <ModifyUpload
193
+ {i18n}
194
+ absolute={false}
195
+ on:clear={() => (selected_image = null)}
196
+ />
197
+ </div>
198
+ <!-- svelte-ignore a11y-click-events-have-key-events -->
199
+ <!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
200
+ <img
201
+ data-testid="detailed-image"
202
+ on:click={(event) => handle_preview_click(event)}
203
+ src={_value[selected_image].image.data}
204
+ alt={_value[selected_image].caption || ""}
205
+ title={_value[selected_image].caption || null}
206
+ class:with-caption={!!_value[selected_image].caption}
207
+ style="height: calc(100% - {_value[selected_image].caption}
208
+ ? '80px'
209
+ : '60px'})"
210
+ loading="lazy"
211
+ />
212
+ {#if _value[selected_image].caption}
213
+ <div class="caption">
214
+ {_value[selected_image].caption}
215
+ </div>
216
+ {/if}
217
+ <div
218
+ bind:this={container_element}
219
+ class="thumbnails scroll-hide"
220
+ data-testid="container_el"
221
+ >
222
+ {#each _value as image, i}
223
+ <button
224
+ bind:this={el[i]}
225
+ on:click={() => (selected_image = i)}
226
+ class="thumbnail-item thumbnail-small"
227
+ class:selected={selected_image === i}
228
+ >
229
+ <img
230
+ src={image.image.data}
231
+ title={image.caption || null}
232
+ alt={image.caption || null}
233
+ loading="lazy"
234
+ />
235
+ </button>
236
+ {/each}
237
+ </div>
238
+ </div>
239
+ {/if}
240
+
241
+ <div
242
+ bind:clientHeight={client_height}
243
+ class="grid-wrap"
244
+ class:fixed-height={!height || height == "auto"}
245
+ >
246
+ <div
247
+ class="grid-container"
248
+ style="--grid-cols:{grid_cols}; --grid-rows:{grid_rows}; --object-fit: {object_fit}; height: {height};"
249
+ class:pt-6={show_label}
250
+ >
251
+ {#if show_share_button}
252
+ <div class="icon-button">
253
+ <ShareButton
254
+ {i18n}
255
+ on:share
256
+ on:error
257
+ value={_value}
258
+ formatter={format_gallery_for_sharing}
259
+ />
260
+ </div>
261
+ {/if}
262
+ {#each _value as entry, i}
263
+ <button
264
+ class="thumbnail-item thumbnail-lg"
265
+ class:selected={selected_image === i}
266
+ on:click={() => (selected_image = i)}
267
+ >
268
+ <img
269
+ alt={entry.caption || ""}
270
+ src={typeof entry.image === "string"
271
+ ? entry.image
272
+ : entry.image.data}
273
+ loading="lazy"
274
+ />
275
+ {#if entry.caption}
276
+ <div class="caption-label">
277
+ {entry.caption}
278
+ </div>
279
+ {/if}
280
+ </button>
281
+ {/each}
282
+ </div>
283
+ </div>
284
+ {/if}
285
+
286
+ <style lang="postcss">
287
+ .preview {
288
+ display: flex;
289
+ position: absolute;
290
+ top: 0px;
291
+ right: 0px;
292
+ bottom: 0px;
293
+ left: 0px;
294
+ flex-direction: column;
295
+ z-index: var(--layer-2);
296
+ backdrop-filter: blur(8px);
297
+ background: var(--background-fill-primary);
298
+ height: var(--size-full);
299
+ }
300
+
301
+ .fixed-height {
302
+ min-height: var(--size-80);
303
+ max-height: 55vh;
304
+ }
305
+
306
+ @media (--screen-xl) {
307
+ .fixed-height {
308
+ min-height: 450px;
309
+ }
310
+ }
311
+
312
+ .preview img {
313
+ width: var(--size-full);
314
+ height: calc(var(--size-full) - 60px);
315
+ object-fit: contain;
316
+ }
317
+
318
+ .preview img.with-caption {
319
+ height: calc(var(--size-full) - 80px);
320
+ }
321
+
322
+ .caption {
323
+ padding: var(--size-2) var(--size-3);
324
+ overflow: hidden;
325
+ color: var(--block-label-text-color);
326
+ font-weight: var(--weight-semibold);
327
+ text-align: center;
328
+ text-overflow: ellipsis;
329
+ white-space: nowrap;
330
+ }
331
+
332
+ .thumbnails {
333
+ display: flex;
334
+ position: absolute;
335
+ bottom: 0;
336
+ justify-content: center;
337
+ align-items: center;
338
+ gap: var(--spacing-lg);
339
+ width: var(--size-full);
340
+ height: var(--size-14);
341
+ overflow-x: scroll;
342
+ }
343
+
344
+ .thumbnail-item {
345
+ --ring-color: transparent;
346
+ position: relative;
347
+ box-shadow:
348
+ 0 0 0 2px var(--ring-color),
349
+ var(--shadow-drop);
350
+ border: 1px solid var(--border-color-primary);
351
+ border-radius: var(--button-small-radius);
352
+ background: var(--background-fill-secondary);
353
+ aspect-ratio: var(--ratio-square);
354
+ width: var(--size-full);
355
+ height: var(--size-full);
356
+ overflow: clip;
357
+ }
358
+
359
+ .thumbnail-item:hover {
360
+ --ring-color: var(--color-accent);
361
+ filter: brightness(1.1);
362
+ }
363
+
364
+ .thumbnail-item.selected {
365
+ --ring-color: var(--color-accent);
366
+ }
367
+
368
+ .thumbnail-small {
369
+ flex: none;
370
+ transform: scale(0.9);
371
+ transition: 0.075s;
372
+ width: var(--size-9);
373
+ height: var(--size-9);
374
+ }
375
+
376
+ .thumbnail-small.selected {
377
+ --ring-color: var(--color-accent);
378
+ transform: scale(1);
379
+ border-color: var(--color-accent);
380
+ }
381
+
382
+ .thumbnail-small > img {
383
+ width: var(--size-full);
384
+ height: var(--size-full);
385
+ overflow: hidden;
386
+ object-fit: var(--object-fit);
387
+ }
388
+
389
+ .grid-wrap {
390
+ position: relative;
391
+ padding: var(--size-2);
392
+ height: var(--size-full);
393
+ overflow-y: scroll;
394
+ }
395
+
396
+ .grid-container {
397
+ display: grid;
398
+ position: relative;
399
+ grid-template-rows: repeat(var(--grid-rows), minmax(100px, 1fr));
400
+ grid-template-columns: repeat(var(--grid-cols), minmax(100px, 1fr));
401
+ grid-auto-rows: minmax(100px, 1fr);
402
+ gap: var(--spacing-lg);
403
+ }
404
+
405
+ .thumbnail-lg > img {
406
+ width: var(--size-full);
407
+ height: var(--size-full);
408
+ overflow: hidden;
409
+ object-fit: var(--object-fit);
410
+ }
411
+
412
+ .thumbnail-lg:hover .caption-label {
413
+ opacity: 0.5;
414
+ }
415
+
416
+ .caption-label {
417
+ position: absolute;
418
+ right: var(--block-label-margin);
419
+ bottom: var(--block-label-margin);
420
+ z-index: var(--layer-1);
421
+ border-top: 1px solid var(--border-color-primary);
422
+ border-left: 1px solid var(--border-color-primary);
423
+ border-radius: var(--block-label-radius);
424
+ background: var(--background-fill-secondary);
425
+ padding: var(--block-label-padding);
426
+ max-width: 80%;
427
+ overflow: hidden;
428
+ font-size: var(--block-label-text-size);
429
+ text-align: left;
430
+ text-overflow: ellipsis;
431
+ white-space: nowrap;
432
+ }
433
+
434
+ .icon-button {
435
+ position: absolute;
436
+ top: 0px;
437
+ right: 0px;
438
+ z-index: var(--layer-1);
439
+ }
440
+
441
+ .icon-buttons {
442
+ display: flex;
443
+ position: absolute;
444
+ right: 0;
445
+ }
446
+
447
+ .icon-buttons a {
448
+ margin: var(--size-1) 0;
449
+ }
450
+ </style>
@@ -0,0 +1,76 @@
1
+ <script lang="ts">
2
+ import type { Gradio, ShareData, SelectData } from "@gradio/utils";
3
+ import { Block } from "@gradio/atoms";
4
+ import Gallery from "./Gallery.svelte";
5
+ import type { LoadingStatus } from "@gradio/statustracker";
6
+ import { StatusTracker } from "@gradio/statustracker";
7
+ import type { FileData } from "@gradio/upload";
8
+
9
+ export let loading_status: LoadingStatus;
10
+ export let show_label: boolean;
11
+ export let label: string;
12
+ export let root: string;
13
+ export let root_url: null | string;
14
+ export let elem_id = "";
15
+ export let elem_classes: string[] = [];
16
+ export let visible = true;
17
+ export let value:
18
+ | { image: FileData; caption: string | null }[]
19
+ | null
20
+ | null = null;
21
+ export let container = true;
22
+ export let scale: number | null = null;
23
+ export let min_width: number | undefined = undefined;
24
+ export let grid_cols: number | number[] | undefined = [2];
25
+ export let grid_rows: number | number[] | undefined = undefined;
26
+ export let height: number | "auto" = "auto";
27
+ export let preview: boolean;
28
+ export let allow_preview = true;
29
+ export let object_fit: "contain" | "cover" | "fill" | "none" | "scale-down" =
30
+ "cover";
31
+ export let show_share_button = false;
32
+ export let show_download_button = false;
33
+ export let gradio: Gradio<{
34
+ select: SelectData;
35
+ share: ShareData;
36
+ error: string;
37
+ }>;
38
+ </script>
39
+
40
+ <Block
41
+ {visible}
42
+ variant="solid"
43
+ padding={false}
44
+ {elem_id}
45
+ {elem_classes}
46
+ {container}
47
+ {scale}
48
+ {min_width}
49
+ allow_overflow={false}
50
+ height={typeof height === "number" ? height : undefined}
51
+ >
52
+ <StatusTracker
53
+ autoscroll={gradio.autoscroll}
54
+ i18n={gradio.i18n}
55
+ {...loading_status}
56
+ />
57
+ <Gallery
58
+ on:select={(e) => gradio.dispatch("select", e.detail)}
59
+ on:share={(e) => gradio.dispatch("share", e.detail)}
60
+ on:error={(e) => gradio.dispatch("error", e.detail)}
61
+ {label}
62
+ {value}
63
+ {show_label}
64
+ {root}
65
+ {root_url}
66
+ {grid_cols}
67
+ {grid_rows}
68
+ {height}
69
+ {preview}
70
+ {object_fit}
71
+ {allow_preview}
72
+ {show_share_button}
73
+ {show_download_button}
74
+ i18n={gradio.i18n}
75
+ />
76
+ </Block>
@@ -0,0 +1 @@
1
+ export { default } from "./StaticGallery.svelte";
@@ -0,0 +1,18 @@
1
+ import { uploadToHuggingFace } from "@gradio/utils";
2
+ import type { FileData } from "@gradio/upload";
3
+
4
+ export async function format_gallery_for_sharing(
5
+ value: [FileData, string | null][] | null
6
+ ): Promise<string> {
7
+ if (!value) return "";
8
+ let urls = await Promise.all(
9
+ value.map(async ([image, _]) => {
10
+ if (image === null) return "";
11
+ return await uploadToHuggingFace(image.data, "url");
12
+ })
13
+ );
14
+
15
+ return `<div style="display: flex; flex-wrap: wrap; gap: 16px">${urls
16
+ .map((url) => `<img src="${url}" style="height: 400px" />`)
17
+ .join("")}</div>`;
18
+ }