You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Creates a gallery component that allows displaying a grid of images, and optionally captions. If used as an input, the user can upload images to the gallery.
48
-
If used as an output, the user can click on individual images to view them at a higher resolution.
53
+
Creates a gallery component that allows displaying a grid of images or videos, and optionally captions. If used as an input, the user can upload images or videos to the gallery.
54
+
If used as an output, the user can click on individual images or videos to view them at a higher resolution.
value: List of images to display in the gallery by default. If callable, the function will be called whenever the app loads to set the initial value of the component.
102
+
value: List of images or videos to display in the gallery by default. If callable, the function will be called whenever the app loads to set the initial value of the component.
96
103
format: Format to save images before they are returned to the frontend, such as 'jpeg' or 'png'. This parameter only applies to images that are returned from the prediction function as numpy arrays or PIL Images. The format should be supported by the PIL library.
104
+
file_types: List of file extensions or types of files to be uploaded (e.g. ['image', 'video']), when this is used as an input component. "image" allows only image files to be uploaded, "video" allows only video files to be uploaded, ".mp4" allows only mp4 files to be uploaded, etc. If None, any image and video files types are allowed.
97
105
label: The label for this component. Appears above the component and is also used as the header if there are a table of examples for this component. If None and used in a `gr.Interface`, the label will be the name of the parameter this component is assigned to.
98
106
every: Continously calls `value` to recalculate it if `value` is a function (has no effect otherwise). Can provide a Timer whose tick resets `value`, or a float that provides the regular interval for the reset Timer.
99
107
inputs: Components that are used as inputs to calculate `value` if `value` is a function (has no effect otherwise). `value` is recalculated any time the inputs change.
payload: a list of images, or list of (image, caption) tuples
179
+
payload: a list of images or videos, or list of (media, caption) tuples
171
180
Returns:
172
-
Passes the list of images as a list of (image, caption) tuples, or a list of (image, None) tuples if no captions are provided (which is usually the case). The image can be a `str` file path, a `numpy` array, or a `PIL.Image` object depending on `type`.
181
+
Passes the list of images or videos as a list of (media, caption) tuples, or a list of (media, None) tuples if no captions are provided (which is usually the case). Images can be a `str` file path, a `numpy` array, or a `PIL.Image` object depending on `type`. Videos are always `str` file path.
value: Expects the function to return a `list` of images, or `list` of (image, `str` caption) tuples. Each image can be a `str` file path, a `numpy` array, or a `PIL.Image` object.
201
+
value: Expects the function to return a `list` of images or videos, or `list` of (media, `str` caption) tuples. Each image can be a `str` file path, a `numpy` array, or a `PIL.Image` object. Each video can be a `str` file path.
189
202
Returns:
190
-
a list of images, or list of (image, caption) tuples
203
+
a list of images or videos, or list of (media, caption) tuples
191
204
"""
192
205
ifvalueisNone:
193
206
returnGalleryData(root=[])
@@ -197,6 +210,7 @@ def _save(img):
197
210
url=None
198
211
caption=None
199
212
orig_name=None
213
+
mime_type=None
200
214
ifisinstance(img, (tuple, list)):
201
215
img, caption=img
202
216
ifisinstance(img, np.ndarray):
@@ -211,6 +225,7 @@ def _save(img):
211
225
file_path=str(utils.abspath(file))
212
226
elifisinstance(img, str):
213
227
file_path=img
228
+
mime_type=client_utils.get_mimetype(file_path)
214
229
ifis_http_url_like(img):
215
230
url=img
216
231
orig_name=Path(urlparse(img).path).name
@@ -220,12 +235,29 @@ def _save(img):
220
235
elifisinstance(img, Path):
221
236
file_path=str(img)
222
237
orig_name=img.name
238
+
mime_type=client_utils.get_mimetype(file_path)
223
239
else:
224
240
raiseValueError(f"Cannot process type as image: {type(img)}")
0 commit comments