From 8f6d672f2f779c9631498dfcb31e8ffcf3b11352 Mon Sep 17 00:00:00 2001 From: Ali Abid Date: Mon, 6 Jul 2020 08:21:08 -0700 Subject: [PATCH] changes --- build/lib/gradio/inputs.py | 4 +++- build/lib/gradio/interface.py | 2 +- build/lib/gradio/static/js/all_io.js | 5 +++-- build/lib/gradio/static/js/interfaces/input/textbox.js | 5 ++++- demo/basic_text.py | 10 +++++++--- gradio/interface.py | 2 +- 6 files changed, 19 insertions(+), 9 deletions(-) diff --git a/build/lib/gradio/inputs.py b/build/lib/gradio/inputs.py index 8d6379bbcd..cc5437c2b5 100644 --- a/build/lib/gradio/inputs.py +++ b/build/lib/gradio/inputs.py @@ -137,10 +137,11 @@ class Webcam(AbstractInput): class Textbox(AbstractInput): - def __init__(self, sample_inputs=None, lines=1, placeholder=None, label=None, numeric=False): + def __init__(self, sample_inputs=None, lines=1, placeholder=None, default=None, label=None, numeric=False): self.sample_inputs = sample_inputs self.lines = lines self.placeholder = placeholder + self.default = default self.numeric = numeric super().__init__(label) @@ -151,6 +152,7 @@ class Textbox(AbstractInput): return { "lines": self.lines, "placeholder": self.placeholder, + "default": self.default, **super().get_template_context() } diff --git a/build/lib/gradio/interface.py b/build/lib/gradio/interface.py index 19c5e63bf4..3c59a26fe0 100644 --- a/build/lib/gradio/interface.py +++ b/build/lib/gradio/interface.py @@ -105,7 +105,7 @@ class Interface: if not iface[1]["label"]: iface[1]["label"] = param.replace("_", " ") for i, iface in enumerate(config["output_interfaces"]): - ret_name = "Output " + str(i) if len(config["output_interfaces"]) > 1 else "Output" + ret_name = "Output " + str(i + 1) if len(config["output_interfaces"]) > 1 else "Output" if not iface[1]["label"]: iface[1]["label"] = ret_name except ValueError: diff --git a/build/lib/gradio/static/js/all_io.js b/build/lib/gradio/static/js/all_io.js index fd32cad1a4..3f5e1d7923 100644 --- a/build/lib/gradio/static/js/all_io.js +++ b/build/lib/gradio/static/js/all_io.js @@ -27,7 +27,8 @@ var io_master_template = { } this.fn(this.last_input).then((output) => { io.output(output); - }).catch(() => { + }).catch((error) => { + console.error(error) this.target.find(".loading_in_progress").hide(); this.target.find(".loading_failed").show(); }) @@ -37,7 +38,7 @@ var io_master_template = { for (let i = 0; i < this.output_interfaces.length; i++) { this.output_interfaces[i].output(data["data"][i]); - this.output_interfaces[i].target.parent().find(`.loading_time[interface="${i}"]`).text("Latency: " + ((data["durations"][i])).toFixed(2) + "s"); + // this.output_interfaces[i].target.parent().find(`.loading_time[interface="${i}"]`).text("Latency: " + ((data["durations"][i])).toFixed(2) + "s"); } if (this.config.live) { this.gather(); diff --git a/build/lib/gradio/static/js/interfaces/input/textbox.js b/build/lib/gradio/static/js/interfaces/input/textbox.js index 258f4cf913..432e8569ec 100644 --- a/build/lib/gradio/static/js/interfaces/input/textbox.js +++ b/build/lib/gradio/static/js/interfaces/input/textbox.js @@ -9,7 +9,10 @@ const textbox_input = { this.target.css("height", "auto"); } if (opts.placeholder) { - this.target.find(".input_text").attr("placeholder", opts.placeholder) + this.target.find(".input_text").attr("placeholder", opts.placeholder); + } + if (opts.default) { + this.target.find(".input_text").val(opts.default); } }, submit: function() { diff --git a/demo/basic_text.py b/demo/basic_text.py index 628e234e5c..6593b01d4f 100644 --- a/demo/basic_text.py +++ b/demo/basic_text.py @@ -1,8 +1,8 @@ import gradio as gr from time import sleep -def answer_question(quantity, animal, place, activity_list, morning): - return f"""The {quantity} {animal}s went to the {place} where they {" and ".join(activity_list)} until the {"morning" if morning else "night"}""" +def answer_question(quantity, animal, place, activity_list, morning, etc): + return f"""The {quantity} {animal}s went to the {place} where they {" and ".join(activity_list)} until the {"morning" if morning else "night"}""", "OK" gr.Interface(answer_question, @@ -12,8 +12,12 @@ gr.Interface(answer_question, gr.inputs.Radio(["park", "zoo", "road"]), gr.inputs.CheckboxGroup(["ran", "swam", "ate", "slept"]), gr.inputs.Checkbox(label="Is it the morning?"), + gr.inputs.Textbox(default="What else?"), ], - gr.outputs.Textbox(label="out", lines=8), + [ + gr.outputs.Textbox(lines=8), + gr.outputs.Textbox(lines=1), + ], examples=[ [2, "cat", "park", ["ran", "swam"], True], [4, "dog", "zoo", ["ate", "swam"], False], diff --git a/gradio/interface.py b/gradio/interface.py index 19c5e63bf4..3c59a26fe0 100644 --- a/gradio/interface.py +++ b/gradio/interface.py @@ -105,7 +105,7 @@ class Interface: if not iface[1]["label"]: iface[1]["label"] = param.replace("_", " ") for i, iface in enumerate(config["output_interfaces"]): - ret_name = "Output " + str(i) if len(config["output_interfaces"]) > 1 else "Output" + ret_name = "Output " + str(i + 1) if len(config["output_interfaces"]) > 1 else "Output" if not iface[1]["label"]: iface[1]["label"] = ret_name except ValueError: