mirror of
https://github.com/gradio-app/gradio.git
synced 2025-01-12 10:34:32 +08:00
added default parameter to slider
This commit is contained in:
parent
20c769a519
commit
002ffc400b
@ -209,15 +209,17 @@ class CheckboxGroup(AbstractInput):
|
||||
|
||||
|
||||
class Slider(AbstractInput):
|
||||
def __init__(self, minimum=0, maximum=100, label=None):
|
||||
def __init__(self, minimum=0, maximum=100, default=None, label=None):
|
||||
self.minimum = minimum
|
||||
self.maximum = maximum
|
||||
self.default = minimum if default is None else default
|
||||
super().__init__(label)
|
||||
|
||||
def get_template_context(self):
|
||||
return {
|
||||
"minimum": self.minimum,
|
||||
"maximum": self.maximum,
|
||||
"default": self.default,
|
||||
**super().get_template_context()
|
||||
}
|
||||
|
||||
|
@ -314,11 +314,12 @@ class Interface:
|
||||
config["share_url"] = share_url
|
||||
|
||||
processed_examples = []
|
||||
for example_set in self.examples:
|
||||
processed_set = []
|
||||
for iface, example in zip(self.input_interfaces, example_set):
|
||||
processed_set.append(iface.process_example(example))
|
||||
processed_examples.append(processed_set)
|
||||
if self.examples:
|
||||
for example_set in self.examples:
|
||||
processed_set = []
|
||||
for iface, example in zip(self.input_interfaces, example_set):
|
||||
processed_set.append(iface.process_example(example))
|
||||
processed_examples.append(processed_set)
|
||||
|
||||
config["examples"] = processed_examples
|
||||
networking.set_config(config, output_directory)
|
||||
|
@ -12,6 +12,7 @@ const slider = {
|
||||
this.target.css("height", "auto");
|
||||
this.target.find(".min").text(opts.minimum);
|
||||
this.target.find(".max").text(opts.maximum);
|
||||
this.target.find(".value").text(opts.default);
|
||||
let difference = opts.maximum - opts.minimum;
|
||||
if (difference <= 1) {
|
||||
step = 0.01;
|
||||
@ -23,6 +24,7 @@ const slider = {
|
||||
this.target.find(".slider")
|
||||
.attr("min", opts.minimum)
|
||||
.attr("max", opts.maximum)
|
||||
.attr("value", opts.default)
|
||||
.attr("step", step)
|
||||
.on("change", function() {
|
||||
io.target.find(".value").text($(this).val());
|
||||
@ -33,7 +35,7 @@ const slider = {
|
||||
this.io_master.input(this.id, parseFloat(value));
|
||||
},
|
||||
clear: function() {
|
||||
this.target.find("input").val(this.minimum);
|
||||
this.target.find("input").val(this.default);
|
||||
},
|
||||
load_example: function(data) {
|
||||
this.target.find("input").val(data);
|
||||
|
Loading…
Reference in New Issue
Block a user