diff --git a/build/lib/gradio/static/css/gradio.css b/build/lib/gradio/static/css/gradio.css index 872608f9f9..f5f39cb8a8 100644 --- a/build/lib/gradio/static/css/gradio.css +++ b/build/lib/gradio/static/css/gradio.css @@ -3,10 +3,15 @@ flex: 1 1 0; display: inline-block; box-sizing: border-box; - margin: 0 30px 14px 0; +} +.panel:first-child { + margin-right: 24px; +} +.panel:last-child { + margin-left: 8px; } .panel_header, .interface { - background-color: #EEEEEE; + background-color: whitesmoke; } .panel_header { text-transform: uppercase; @@ -31,7 +36,6 @@ } .loading img { display: none; - height: 18px; } .panel_buttons { display: flex; @@ -44,7 +48,7 @@ display: none; } .submit, .clear, .panel_button { - background-color: #EEEEEE !important; + background-color: whitesmoke !important; flex-grow: 1; padding: 8px !important; box-sizing: border-box; @@ -62,7 +66,7 @@ } .flag_message { padding: 8px !important; - background-color: #EEEEEE !important; + background-color: whitesmoke !important; } .upload_zone { @@ -111,7 +115,7 @@ .flag.flagged { background-color: pink !important; } -#loading { +.loading { justify-content: center; align-items: center; } diff --git a/build/lib/gradio/static/css/interfaces/input/csv.css b/build/lib/gradio/static/css/interfaces/input/csv.css index e186abab65..afbc4e6ff6 100644 --- a/build/lib/gradio/static/css/interfaces/input/csv.css +++ b/build/lib/gradio/static/css/interfaces/input/csv.css @@ -22,5 +22,5 @@ padding: 2px 4px; } .csv_preview td:nth-child(even) { - background-color: #EEEEEE; + background-color: whitesmoke; } diff --git a/build/lib/gradio/static/css/style.css b/build/lib/gradio/static/css/style.css index cc33f6d1aa..ce100507eb 100644 --- a/build/lib/gradio/static/css/style.css +++ b/build/lib/gradio/static/css/style.css @@ -14,9 +14,6 @@ button, input[type="submit"], input[type="reset"], input[type="text"], input[typ -webkit-appearance: none; border-radius: 0; } -nav, #panels, #share_row { - margin-left: 30px; -} nav { text-align: center; padding: 16px 0 4px; @@ -48,11 +45,14 @@ nav img { #share_row, #share_complete, #share_form { display: none; } -#panels { +.panels { display: flex; flex-flow: row; flex-wrap: wrap; justify-content: center; + max-width: 1028px; + width: 100%; + margin: 0 auto; } button.primary { color: white; @@ -67,7 +67,7 @@ button.secondary { } #featured_table { border-collapse: collapse; - border: solid 2px #EEEEEE; + border: solid 2px whitesmoke; margin-bottom: 20px; table-layout: fixed; } @@ -81,7 +81,7 @@ button.secondary { overflow-y: auto; } #featured_table div:nth-child(even) { - background-color: #EEEEEE; + background-color: whitesmoke; } #featured_table div:hover { background-color: #EEA45D; diff --git a/build/lib/gradio/static/js/all_io.js b/build/lib/gradio/static/js/all_io.js index 31212910b6..aff7a19430 100644 --- a/build/lib/gradio/static/js/all_io.js +++ b/build/lib/gradio/static/js/all_io.js @@ -1,4 +1,4 @@ -var io_master = { +var io_master_template = { gather: function() { this.clear(); for (let iface of this.input_interfaces) { @@ -17,45 +17,32 @@ var io_master = { } }, submit: function() { - var post_data = { - 'data': this.last_input - }; - if (!config.live) { - $("#loading").removeClass("invisible"); - $("#loading_in_progress").show(); - $("#loading_failed").hide(); - $(".output_interface").addClass("invisible"); + let io = this; + if (!this.config.live) { + this.target.find(".loading").removeClass("invisible"); + this.target.find(".loading_in_progress").show(); + this.target.find(".loading_failed").hide(); + this.target.find(".output_interface").addClass("invisible"); + this.target.find(".output_interfaces .panel_header").addClass("invisible"); } - $.ajax({type: "POST", - url: "/api/predict/", - data: JSON.stringify(post_data), - success: function(output){ - if (output['action'] == 'output') { - io_master.output(output); - } - }, - error: function(XMLHttpRequest, textStatus, errorThrown) { - $("#loading_in_progress").hide(); - $("#loading_failed").show(); - console.log(XMLHttpRequest); - console.log(textStatus); - console.log(errorThrown); - } - }); + this.fn(this.last_input).then((output) => { + io.output(output); + }).catch(() => { + this.target.find(".loading_in_progress").hide(); + this.target.find(".loading_failed").show(); + }) }, output: function(data) { this.last_output = data["data"]; for (let i = 0; i < this.output_interfaces.length; i++) { this.output_interfaces[i].output(data["data"][i]); } - // if (this.input_interface.output && data["saliency"]) { - // this.input_interface.output(data["saliency"]); - // } - if (config.live) { + if (this.config.live) { this.gather(); } else { - $("#loading").addClass("invisible"); - $(".output_interface").removeClass("invisible"); + this.target.find(".loading").addClass("invisible"); + this.target.find(".output_interface").removeClass("invisible"); + this.target.find(".output_interfaces .panel_header").removeClass("invisible"); } }, flag: function(message) { diff --git a/build/lib/gradio/static/js/gradio.js b/build/lib/gradio/static/js/gradio.js new file mode 100644 index 0000000000..16e0d9d5e8 --- /dev/null +++ b/build/lib/gradio/static/js/gradio.js @@ -0,0 +1,130 @@ +function gradio(config, fn, target) { + target = $(target); + target.html(` +
+
+
+
+
+ + +
+
+
+ +
+
+
+
`); + let io_master = Object.create(io_master_template); + io_master.fn = fn + io_master.target = target; + io_master.config = config; + + let input_to_object_map = { + "csv" : {}, + "imagein" : image_input, + "sketchpad" : sketchpad_input, + "textbox" : textbox_input, + "webcam" : webcam, + "microphone" : microphone, + "radio" : radio, + "checkbox" : checkbox, + "checkboxgroup" : checkbox_group, + "slider" : slider, + "dropdown" : dropdown, + } + let output_to_object_map = { + "csv" : {}, + "image" : image_output, + "label" : label_output, + "textbox" : textbox_output + } + let id_to_interface_map = {} + + function set_interface_id(interface, id) { + interface.id = id; + id_to_interface_map[id] = interface; + } + + _id = 0; + let input_interfaces = []; + let output_interfaces = []; + for (let i = 0; i < config["input_interfaces"].length; i++) { + input_interface_data = config["input_interfaces"][i]; + input_interface = Object.create(input_to_object_map[input_interface_data[0]]); + if (input_interface_data[1]["label"]) { + target.find(".input_interfaces").append(` +
${input_interface_data[1]["label"]} + `); + } + target.find(".input_interfaces").append(` +
+ ${input_interface.html} +
+ `); + input_interface.target = target.find(`.input_interface[interface_id=${_id}]`); + set_interface_id(input_interface, _id); + input_interface.init(input_interface_data[1]); + input_interfaces.push(input_interface); + input_interface.io_master = io_master; + _id++; + } + for (let i = 0; i < config["output_interfaces"].length; i++) { + if (i != 0 && i % (config["output_interfaces"].length / config.function_count) == 0) { + target.find(".output_interfaces").append("
"); + } + output_interface_data = config["output_interfaces"][i]; + output_interface = Object.create(output_to_object_map[ + output_interface_data[0]]); + if (output_interface_data[1]["label"]) { + target.find(".output_interfaces").append(` +
${output_interface_data[1]["label"]} + `); + } + target.find(".output_interfaces").append(` +
+ ${output_interface.html} +
+ `); + output_interface.target = target.find(`.output_interface[interface_id=${_id}]`); + set_interface_id(output_interface, _id); + output_interface.init(output_interface_data[1]); + output_interfaces.push(output_interface); + output_interface.io_master = io_master; + _id++; + } + io_master.input_interfaces = input_interfaces; + io_master.output_interfaces = output_interfaces; + target.find(".clear").click(function() { + for (let input_interface of input_interfaces) { + input_interface.clear(); + } + for (let output_interface of output_interfaces) { + output_interface.clear(); + } + target.find(".flag").removeClass("flagged"); + target.find(".flag_message").empty(); + target.find(".loading").addClass("invisible"); + target.find(".output_interface").removeClass("invisible"); + io_master.last_input = null; + io_master.last_output = null; + }); + if (config.live) { + io_master.gather(); + } else { + target.find(".submit").show(); + target.find(".submit").click(function() { + io_master.gather(); + target.find(".flag").removeClass("flagged"); + }) + } + if (!config.show_input) { + target.find(".input_panel").hide(); + } + + return io_master; +} \ No newline at end of file diff --git a/build/lib/gradio/static/js/interfaces/input/sketchpad.js b/build/lib/gradio/static/js/interfaces/input/sketchpad.js index 123fc00ce2..339d4a0555 100644 --- a/build/lib/gradio/static/js/interfaces/input/sketchpad.js +++ b/build/lib/gradio/static/js/interfaces/input/sketchpad.js @@ -27,7 +27,7 @@ const sketchpad_input = { var dimension = Math.min(this.target.find(".canvas_holder").width(), this.target.find(".canvas_holder").height()) - 2 // dimension - border var id = this.id; - if (config.disabled) { + if (this.io_master.config.disabled) { this.target.find('.canvas_holder canvas') .attr("width", dimension).attr("height", dimension); } else { diff --git a/build/lib/gradio/static/js/interfaces/input/webcam.js b/build/lib/gradio/static/js/interfaces/input/webcam.js index 3fcfee70b6..6db92d5c69 100644 --- a/build/lib/gradio/static/js/interfaces/input/webcam.js +++ b/build/lib/gradio/static/js/interfaces/input/webcam.js @@ -11,7 +11,7 @@ const webcam = { // this.target.find(".webcam_box").width(this.target.find(".webcam_box").width); let w = this.target.find(".webcam_box").width(); let h = this.target.find(".webcam_box").height(); - if (config.live) { + if (this.io_master.config.live) { this.target.find(".take_photo").hide(); } let RATIO = 4/3; @@ -45,7 +45,7 @@ const webcam = { }, submit: function() { var io = this; - if (config.live) { + if (this.io_master.config.live) { if (this.state == "CAMERA_ON") { Webcam.snap(function(image_data) { this.io_master.input(io.id, image_data); diff --git a/build/lib/gradio/templates/index.html b/build/lib/gradio/templates/index.html index c698ee20a3..4c6f1db6e8 100644 --- a/build/lib/gradio/templates/index.html +++ b/build/lib/gradio/templates/index.html @@ -41,33 +41,7 @@
-
-
-
-
-
- - -
-
-
- -
-
-
- - -
-
-
- +
@@ -102,7 +76,20 @@ - - + + diff --git a/demo/basic_text.py b/demo/basic_text.py index a820f66df3..228adeabb4 100644 --- a/demo/basic_text.py +++ b/demo/basic_text.py @@ -1,15 +1,14 @@ import gradio as gr -def upper(choice, sentence): - return sentence[::-1], choice.upper() +def answer_question(text1, text2): + return text1, text2, {"plagiarism": 0.62, "original": 0.38} -gr.Interface(upper, +gr.Interface(answer_question, [ - gr.inputs.Dropdown(label="Pick something", choices=["big thing", "small", "other"]), - "text" - ], - [ - "textbox", - gr.outputs.Textbox(label="box 2", lines=3, placeholder="hello") - ]).launch() + gr.inputs.Microphone(label="speech"), + gr.inputs.Dropdown(["Deepspeech", "Sphynx", "Wav2Text"], label="model"), + ], [ + gr.outputs.Textbox(label="text 1", lines=8), + ] + ).launch() diff --git a/demo/form_graph.py b/demo/form_graph.py index b23ec37c2b..fdd88e3c1e 100644 --- a/demo/form_graph.py +++ b/demo/form_graph.py @@ -26,4 +26,6 @@ gr.Interface(plot_forecast, gr.inputs.Slider(1, 100, label="Noise Level"), gr.inputs.Checkbox(label="Show Legend"), gr.inputs.Dropdown(["cross", "line", "circle"], label="Style"), - ], "plot").launch() + ], + gr.outputs.Image(plot=True, label="forecast") + ).launch() diff --git a/dist/gradio-0.9.1-py3.6.egg b/dist/gradio-0.9.1-py3.6.egg new file mode 100644 index 0000000000..34e4821c2e Binary files /dev/null and b/dist/gradio-0.9.1-py3.6.egg differ diff --git a/dist/gradio-0.9.1-py3.7.egg b/dist/gradio-0.9.1-py3.7.egg index 35d678fc3a..0836a16925 100644 Binary files a/dist/gradio-0.9.1-py3.7.egg and b/dist/gradio-0.9.1-py3.7.egg differ diff --git a/gradio.egg-info/SOURCES.txt b/gradio.egg-info/SOURCES.txt index 23be383c79..6e4c0c1c5f 100644 --- a/gradio.egg-info/SOURCES.txt +++ b/gradio.egg-info/SOURCES.txt @@ -50,8 +50,7 @@ gradio/static/img/vendor/icon-b.svg gradio/static/img/vendor/icon-c.svg gradio/static/img/vendor/icon-d.svg gradio/static/js/all_io.js -gradio/static/js/load_history.js -gradio/static/js/load_interfaces.js +gradio/static/js/gradio.js gradio/static/js/share.js gradio/static/js/utils.js gradio/static/js/interfaces/input/checkbox.js diff --git a/gradio/static/css/gradio.css b/gradio/static/css/gradio.css index 872608f9f9..f5f39cb8a8 100644 --- a/gradio/static/css/gradio.css +++ b/gradio/static/css/gradio.css @@ -3,10 +3,15 @@ flex: 1 1 0; display: inline-block; box-sizing: border-box; - margin: 0 30px 14px 0; +} +.panel:first-child { + margin-right: 24px; +} +.panel:last-child { + margin-left: 8px; } .panel_header, .interface { - background-color: #EEEEEE; + background-color: whitesmoke; } .panel_header { text-transform: uppercase; @@ -31,7 +36,6 @@ } .loading img { display: none; - height: 18px; } .panel_buttons { display: flex; @@ -44,7 +48,7 @@ display: none; } .submit, .clear, .panel_button { - background-color: #EEEEEE !important; + background-color: whitesmoke !important; flex-grow: 1; padding: 8px !important; box-sizing: border-box; @@ -62,7 +66,7 @@ } .flag_message { padding: 8px !important; - background-color: #EEEEEE !important; + background-color: whitesmoke !important; } .upload_zone { @@ -111,7 +115,7 @@ .flag.flagged { background-color: pink !important; } -#loading { +.loading { justify-content: center; align-items: center; } diff --git a/gradio/static/css/interfaces/input/csv.css b/gradio/static/css/interfaces/input/csv.css index e186abab65..afbc4e6ff6 100644 --- a/gradio/static/css/interfaces/input/csv.css +++ b/gradio/static/css/interfaces/input/csv.css @@ -22,5 +22,5 @@ padding: 2px 4px; } .csv_preview td:nth-child(even) { - background-color: #EEEEEE; + background-color: whitesmoke; } diff --git a/gradio/static/css/style.css b/gradio/static/css/style.css index cc33f6d1aa..ce100507eb 100644 --- a/gradio/static/css/style.css +++ b/gradio/static/css/style.css @@ -14,9 +14,6 @@ button, input[type="submit"], input[type="reset"], input[type="text"], input[typ -webkit-appearance: none; border-radius: 0; } -nav, #panels, #share_row { - margin-left: 30px; -} nav { text-align: center; padding: 16px 0 4px; @@ -48,11 +45,14 @@ nav img { #share_row, #share_complete, #share_form { display: none; } -#panels { +.panels { display: flex; flex-flow: row; flex-wrap: wrap; justify-content: center; + max-width: 1028px; + width: 100%; + margin: 0 auto; } button.primary { color: white; @@ -67,7 +67,7 @@ button.secondary { } #featured_table { border-collapse: collapse; - border: solid 2px #EEEEEE; + border: solid 2px whitesmoke; margin-bottom: 20px; table-layout: fixed; } @@ -81,7 +81,7 @@ button.secondary { overflow-y: auto; } #featured_table div:nth-child(even) { - background-color: #EEEEEE; + background-color: whitesmoke; } #featured_table div:hover { background-color: #EEA45D; diff --git a/gradio/static/js/all_io.js b/gradio/static/js/all_io.js index 31212910b6..aff7a19430 100644 --- a/gradio/static/js/all_io.js +++ b/gradio/static/js/all_io.js @@ -1,4 +1,4 @@ -var io_master = { +var io_master_template = { gather: function() { this.clear(); for (let iface of this.input_interfaces) { @@ -17,45 +17,32 @@ var io_master = { } }, submit: function() { - var post_data = { - 'data': this.last_input - }; - if (!config.live) { - $("#loading").removeClass("invisible"); - $("#loading_in_progress").show(); - $("#loading_failed").hide(); - $(".output_interface").addClass("invisible"); + let io = this; + if (!this.config.live) { + this.target.find(".loading").removeClass("invisible"); + this.target.find(".loading_in_progress").show(); + this.target.find(".loading_failed").hide(); + this.target.find(".output_interface").addClass("invisible"); + this.target.find(".output_interfaces .panel_header").addClass("invisible"); } - $.ajax({type: "POST", - url: "/api/predict/", - data: JSON.stringify(post_data), - success: function(output){ - if (output['action'] == 'output') { - io_master.output(output); - } - }, - error: function(XMLHttpRequest, textStatus, errorThrown) { - $("#loading_in_progress").hide(); - $("#loading_failed").show(); - console.log(XMLHttpRequest); - console.log(textStatus); - console.log(errorThrown); - } - }); + this.fn(this.last_input).then((output) => { + io.output(output); + }).catch(() => { + this.target.find(".loading_in_progress").hide(); + this.target.find(".loading_failed").show(); + }) }, output: function(data) { this.last_output = data["data"]; for (let i = 0; i < this.output_interfaces.length; i++) { this.output_interfaces[i].output(data["data"][i]); } - // if (this.input_interface.output && data["saliency"]) { - // this.input_interface.output(data["saliency"]); - // } - if (config.live) { + if (this.config.live) { this.gather(); } else { - $("#loading").addClass("invisible"); - $(".output_interface").removeClass("invisible"); + this.target.find(".loading").addClass("invisible"); + this.target.find(".output_interface").removeClass("invisible"); + this.target.find(".output_interfaces .panel_header").removeClass("invisible"); } }, flag: function(message) { diff --git a/gradio/static/js/gradio.js b/gradio/static/js/gradio.js new file mode 100644 index 0000000000..16e0d9d5e8 --- /dev/null +++ b/gradio/static/js/gradio.js @@ -0,0 +1,130 @@ +function gradio(config, fn, target) { + target = $(target); + target.html(` +
+
+
+
+
+ + +
+
+
+ +
+
+
+
`); + let io_master = Object.create(io_master_template); + io_master.fn = fn + io_master.target = target; + io_master.config = config; + + let input_to_object_map = { + "csv" : {}, + "imagein" : image_input, + "sketchpad" : sketchpad_input, + "textbox" : textbox_input, + "webcam" : webcam, + "microphone" : microphone, + "radio" : radio, + "checkbox" : checkbox, + "checkboxgroup" : checkbox_group, + "slider" : slider, + "dropdown" : dropdown, + } + let output_to_object_map = { + "csv" : {}, + "image" : image_output, + "label" : label_output, + "textbox" : textbox_output + } + let id_to_interface_map = {} + + function set_interface_id(interface, id) { + interface.id = id; + id_to_interface_map[id] = interface; + } + + _id = 0; + let input_interfaces = []; + let output_interfaces = []; + for (let i = 0; i < config["input_interfaces"].length; i++) { + input_interface_data = config["input_interfaces"][i]; + input_interface = Object.create(input_to_object_map[input_interface_data[0]]); + if (input_interface_data[1]["label"]) { + target.find(".input_interfaces").append(` +
${input_interface_data[1]["label"]} + `); + } + target.find(".input_interfaces").append(` +
+ ${input_interface.html} +
+ `); + input_interface.target = target.find(`.input_interface[interface_id=${_id}]`); + set_interface_id(input_interface, _id); + input_interface.init(input_interface_data[1]); + input_interfaces.push(input_interface); + input_interface.io_master = io_master; + _id++; + } + for (let i = 0; i < config["output_interfaces"].length; i++) { + if (i != 0 && i % (config["output_interfaces"].length / config.function_count) == 0) { + target.find(".output_interfaces").append("
"); + } + output_interface_data = config["output_interfaces"][i]; + output_interface = Object.create(output_to_object_map[ + output_interface_data[0]]); + if (output_interface_data[1]["label"]) { + target.find(".output_interfaces").append(` +
${output_interface_data[1]["label"]} + `); + } + target.find(".output_interfaces").append(` +
+ ${output_interface.html} +
+ `); + output_interface.target = target.find(`.output_interface[interface_id=${_id}]`); + set_interface_id(output_interface, _id); + output_interface.init(output_interface_data[1]); + output_interfaces.push(output_interface); + output_interface.io_master = io_master; + _id++; + } + io_master.input_interfaces = input_interfaces; + io_master.output_interfaces = output_interfaces; + target.find(".clear").click(function() { + for (let input_interface of input_interfaces) { + input_interface.clear(); + } + for (let output_interface of output_interfaces) { + output_interface.clear(); + } + target.find(".flag").removeClass("flagged"); + target.find(".flag_message").empty(); + target.find(".loading").addClass("invisible"); + target.find(".output_interface").removeClass("invisible"); + io_master.last_input = null; + io_master.last_output = null; + }); + if (config.live) { + io_master.gather(); + } else { + target.find(".submit").show(); + target.find(".submit").click(function() { + io_master.gather(); + target.find(".flag").removeClass("flagged"); + }) + } + if (!config.show_input) { + target.find(".input_panel").hide(); + } + + return io_master; +} \ No newline at end of file diff --git a/gradio/static/js/interfaces/input/sketchpad.js b/gradio/static/js/interfaces/input/sketchpad.js index 123fc00ce2..339d4a0555 100644 --- a/gradio/static/js/interfaces/input/sketchpad.js +++ b/gradio/static/js/interfaces/input/sketchpad.js @@ -27,7 +27,7 @@ const sketchpad_input = { var dimension = Math.min(this.target.find(".canvas_holder").width(), this.target.find(".canvas_holder").height()) - 2 // dimension - border var id = this.id; - if (config.disabled) { + if (this.io_master.config.disabled) { this.target.find('.canvas_holder canvas') .attr("width", dimension).attr("height", dimension); } else { diff --git a/gradio/static/js/interfaces/input/webcam.js b/gradio/static/js/interfaces/input/webcam.js index 3fcfee70b6..6db92d5c69 100644 --- a/gradio/static/js/interfaces/input/webcam.js +++ b/gradio/static/js/interfaces/input/webcam.js @@ -11,7 +11,7 @@ const webcam = { // this.target.find(".webcam_box").width(this.target.find(".webcam_box").width); let w = this.target.find(".webcam_box").width(); let h = this.target.find(".webcam_box").height(); - if (config.live) { + if (this.io_master.config.live) { this.target.find(".take_photo").hide(); } let RATIO = 4/3; @@ -45,7 +45,7 @@ const webcam = { }, submit: function() { var io = this; - if (config.live) { + if (this.io_master.config.live) { if (this.state == "CAMERA_ON") { Webcam.snap(function(image_data) { this.io_master.input(io.id, image_data); diff --git a/gradio/static/js/load_history.js b/gradio/static/js/load_history.js deleted file mode 100644 index 47bea09de4..0000000000 --- a/gradio/static/js/load_history.js +++ /dev/null @@ -1,20 +0,0 @@ -history_count = 0; -entry_history = []; - -function add_history(entry) { - $("#featured_table").append(` -
${io_master.input_interface.renderFeatured(entry)}
- `); - entry_history.push(entry); - history_count++; -} - -function load_history(data) { - data.forEach(add_history) -} - -$('body').on('click', "#featured_table div", function() { - let entry = entry_history[$(this).attr("entry")]; - io_master.input_interface.loadFeatured(entry); - io_master.output_interface.clear(); -}) diff --git a/gradio/static/js/load_interfaces.js b/gradio/static/js/load_interfaces.js deleted file mode 100644 index 75f5875fca..0000000000 --- a/gradio/static/js/load_interfaces.js +++ /dev/null @@ -1,119 +0,0 @@ -input_to_object_map = { - "csv" : {}, - "imagein" : image_input, - "sketchpad" : sketchpad_input, - "textbox" : textbox_input, - "webcam" : webcam, - "microphone" : microphone, - "radio" : radio, - "checkbox" : checkbox, - "checkboxgroup" : checkbox_group, - "slider" : slider, - "dropdown" : dropdown, -} -output_to_object_map = { - "csv" : {}, - "image" : image_output, - "label" : label_output, - "textbox" : textbox_output -} -id_to_interface_map = {} - -function set_interface_id(interface, id) { - interface.id = id; - id_to_interface_map[id] = interface; -} - -var config; -$.getJSON("static/config.json", function(data) { - config = data; - _id = 0; - let input_interfaces = []; - let output_interfaces = []; - for (let i = 0; i < config["input_interfaces"].length; i++) { - input_interface_data = config["input_interfaces"][i]; - input_interface = Object.create(input_to_object_map[input_interface_data[0]]); - if (input_interface_data[1]["label"]) { - $(".input_interfaces").append(` -
${input_interface_data[1]["label"]} - `); - } - $(".input_interfaces").append(` -
- ${input_interface.html} -
- `); - input_interface.target = $(`.input_interface[interface_id=${_id}]`); - set_interface_id(input_interface, _id); - input_interface.init(input_interface_data[1]); - input_interfaces.push(input_interface); - input_interface.io_master = io_master; - _id++; - } - for (let i = 0; i < config["output_interfaces"].length; i++) { - if (i != 0 && i % (config["output_interfaces"].length / config.function_count) == 0) { - $(".output_interfaces").append("
"); - } - output_interface_data = config["output_interfaces"][i]; - output_interface = Object.create(output_to_object_map[ - output_interface_data[0]]); - if (output_interface_data[1]["label"]) { - $(".output_interfaces").append(` -
${output_interface_data[1]["label"]} - `); - } - $(".output_interfaces").append(` -
- ${output_interface.html} -
- `); - output_interface.target = $(`.output_interface[interface_id=${_id}]`); - set_interface_id(output_interface, _id); - output_interface.init(output_interface_data[1]); - output_interfaces.push(output_interface); - output_interface.io_master = io_master; - _id++; - } - io_master.input_interfaces = input_interfaces; - io_master.output_interfaces = output_interfaces; - $(".clear").click(function() { - for (let input_interface of input_interfaces) { - input_interface.clear(); - } - for (let output_interface of output_interfaces) { - output_interface.clear(); - } - $(".flag").removeClass("flagged"); - $(".flag_message").empty(); - $("#loading").addClass("invisible"); - $(".output_interface").removeClass("invisible"); - io_master.last_input = null; - io_master.last_output = null; - }) - if (config["share_url"] != "None") { - $("#share_row").css('display', 'flex'); - } - load_history(config["sample_inputs"] || []); - if (!config["sample_inputs"]) { - $("#featured_history").hide(); - } - if (config.live) { - io_master.gather(); - } else { - $(".submit").show(); - $(".submit").click(function() { - io_master.gather(); - $(".flag").removeClass("flagged"); - }) - } - if (!config.show_input) { - $(".input_panel").hide(); - } -}); - -$('body').on('click', '.flag', function(e) { - if (io_master.last_output) { - $(".flag").addClass("flagged"); - io_master.flag($(".flag_message").val()); - } -}) diff --git a/gradio/templates/index.html b/gradio/templates/index.html index c698ee20a3..4c6f1db6e8 100644 --- a/gradio/templates/index.html +++ b/gradio/templates/index.html @@ -41,33 +41,7 @@
-
-
-
-
-
- - -
-
-
- -
-
-
- - -
-
-
- +
@@ -102,7 +76,20 @@ - - + +