mirror of
https://github.com/gradio-app/gradio.git
synced 2025-01-06 10:25:17 +08:00
Merge branch 'master' of https://github.com/gradio-app/gradio
This commit is contained in:
commit
d8a00eca55
@ -241,11 +241,12 @@ class Image(InputComponent):
|
||||
Input type: Union[numpy.array, PIL.Image, str]
|
||||
"""
|
||||
|
||||
def __init__(self, shape=None, image_mode='RGB', source="upload", type="numpy", label=None):
|
||||
def __init__(self, shape=None, image_mode='RGB', invert_colors=False, source="upload", type="numpy", label=None):
|
||||
'''
|
||||
Parameters:
|
||||
shape (Tuple[int, int]): shape to crop and resize image to; if None, matches input image size.
|
||||
image_mode (str): "RGB" if color, or "L" if black and white.
|
||||
invert_colors (bool): whether to invert the image as a preprocessing step.
|
||||
source (str): Source of image. "upload" creates a box where user can drop an image file, "webcam" allows user to take snapshot from their webcam, "canvas" defaults to a white image that can be edited and drawn upon with tools.
|
||||
type (str): Type of value to be returned by component. "numpy" returns a numpy array with shape (width, height, 3), "pil" returns a PIL image object, "file" returns a temporary file object whose path can be retrieved by file_obj.name.
|
||||
label (str): component name in interface.
|
||||
@ -254,6 +255,7 @@ class Image(InputComponent):
|
||||
self.image_mode = image_mode
|
||||
self.source = source
|
||||
self.type = type
|
||||
self.invert_colors = invert_colors
|
||||
super().__init__(label)
|
||||
|
||||
@classmethod
|
||||
@ -261,7 +263,7 @@ class Image(InputComponent):
|
||||
return {
|
||||
"image": {},
|
||||
"webcam": {"source": "webcam"},
|
||||
"sketchpad": {"image_mode": "L", "source": "canvas"},
|
||||
"sketchpad": {"image_mode": "L", "source": "canvas", "shape": (28, 28), "invert_colors": True},
|
||||
}
|
||||
|
||||
def get_template_context(self):
|
||||
@ -279,6 +281,8 @@ class Image(InputComponent):
|
||||
if self.shape is not None:
|
||||
im = processing_utils.resize_and_crop(
|
||||
im, (self.shape[0], self.shape[1]))
|
||||
if self.invert_colors:
|
||||
im = PIL.ImageOps.invert(im)
|
||||
if self.type == "pil":
|
||||
return im
|
||||
elif self.type == "numpy":
|
||||
|
Loading…
Reference in New Issue
Block a user