This commit is contained in:
Ali Abid 2020-07-06 08:21:08 -07:00
parent 0cfd220a2f
commit 8f6d672f2f
6 changed files with 19 additions and 9 deletions

View File

@ -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()
}

View File

@ -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:

View File

@ -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();

View File

@ -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() {

View File

@ -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(lines=8),
gr.outputs.Textbox(lines=1),
],
gr.outputs.Textbox(label="out", lines=8),
examples=[
[2, "cat", "park", ["ran", "swam"], True],
[4, "dog", "zoo", ["ate", "swam"], False],

View File

@ -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: