From 665520cc6219ca235f15711934a63ad9b84e26c2 Mon Sep 17 00:00:00 2001 From: Ali Abid Date: Wed, 19 Aug 2020 14:27:22 -0700 Subject: [PATCH] demo updates --- build/lib/gradio/inputs.py | 8 +- .../static/js/interfaces/output/key_values.js | 2 +- build/lib/gradio/templates/index.html | 152 +++++++++--------- demo/all.py | 31 ---- demo/diff_texts.py | 21 +++ demo/digit_classifier.py | 2 +- demo/{records.py => filter_records.py} | 3 +- demo/flip_image.py | 26 --- demo/generate_tone.py | 22 +++ demo/image_mod.py | 21 +++ demo/{matrix.py => matrix_transpose.py} | 0 demo/multi1.py | 32 ---- demo/{basic_text.py => sentence_builder.py} | 4 +- demo/{form_graph.py => stock_forecast.py} | 10 +- demo/text_analysis.py | 30 ++++ .../static/js/interfaces/output/key_values.js | 2 +- gradio/templates/index.html | 152 +++++++++--------- 17 files changed, 264 insertions(+), 254 deletions(-) delete mode 100644 demo/all.py create mode 100644 demo/diff_texts.py rename demo/{records.py => filter_records.py} (81%) delete mode 100644 demo/flip_image.py create mode 100644 demo/generate_tone.py create mode 100644 demo/image_mod.py rename demo/{matrix.py => matrix_transpose.py} (100%) delete mode 100644 demo/multi1.py rename demo/{basic_text.py => sentence_builder.py} (88%) rename demo/{form_graph.py => stock_forecast.py} (74%) create mode 100644 demo/text_analysis.py diff --git a/build/lib/gradio/inputs.py b/build/lib/gradio/inputs.py index 401c8cda3e..37dd72e4ce 100644 --- a/build/lib/gradio/inputs.py +++ b/build/lib/gradio/inputs.py @@ -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": diff --git a/build/lib/gradio/static/js/interfaces/output/key_values.js b/build/lib/gradio/static/js/interfaces/output/key_values.js index 844b27f440..4a9a0ac909 100644 --- a/build/lib/gradio/static/js/interfaces/output/key_values.js +++ b/build/lib/gradio/static/js/interfaces/output/key_values.js @@ -11,7 +11,7 @@ const key_values = { init: function(opts) {}, output: function(data) { let html = "" - for (const [key, value] of Object.entries(data)) { + for (const [key, value] of data) { html += ` ${key} ${value} diff --git a/build/lib/gradio/templates/index.html b/build/lib/gradio/templates/index.html index 7aaff9e876..3053940a3d 100644 --- a/build/lib/gradio/templates/index.html +++ b/build/lib/gradio/templates/index.html @@ -29,37 +29,37 @@ Gradio - - - - - - - + + + + + + + - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + @@ -68,54 +68,54 @@ - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + +