diff --git a/gradio/static/css/interfaces/input/image_upload.css b/gradio/static/css/interfaces/input/image_upload.css
index 3e8ff4c7f2..0d5fa51552 100644
--- a/gradio/static/css/interfaces/input/image_upload.css
+++ b/gradio/static/css/interfaces/input/image_upload.css
@@ -4,13 +4,34 @@
.image_display {
height: 100%;
}
-.image_preview_holder {
+.view_holders {
flex-grow: 1;
height: calc(100% - 36px);
+ background-color: #CCCCCC;
+ position: relative;
+}
+.image_preview_holder, .saliency_holder {
+ width: 100%;
+ height: 100%;
display: flex;
justify-content: center;
align-items: center;
- background-color: #CCCCCC;
+}
+.saliency_holder {
+ position: absolute;
+ top: 0;
+}
+.saliency {
+ display: flex;
+ flex-direction: column;
+}
+.saliency > div {
+ display: flex;
+ flex-grow: 1;
+}
+.saliency > div > div {
+ flex-grow: 1;
+ background-color: #EEA45D;
}
.image_preview {
max-width: 100%;
diff --git a/gradio/static/js/all_io.js b/gradio/static/js/all_io.js
index 7624e5775d..7fb49f9c1c 100644
--- a/gradio/static/js/all_io.js
+++ b/gradio/static/js/all_io.js
@@ -10,7 +10,7 @@ var io_master = {
data: JSON.stringify(post_data),
success: function(output){
if (output['action'] == 'output') {
- io_master.output(output['data']);
+ io_master.output(output);
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
@@ -21,8 +21,11 @@ var io_master = {
});
},
output: function(data) {
- this.last_output = data;
- this.output_interface.output(data);
+ this.last_output = data["data"];
+ this.output_interface.output(data["data"]);
+ if (this.input_interface.output && data["saliency"]) {
+ this.input_interface.output(data["saliency"]);
+ }
},
flag: function(message) {
var post_data = {
diff --git a/gradio/static/js/interfaces/input/image_upload.js b/gradio/static/js/interfaces/input/image_upload.js
index 2d5d5ef9c4..d344c5b293 100644
--- a/gradio/static/js/interfaces/input/image_upload.js
+++ b/gradio/static/js/interfaces/input/image_upload.js
@@ -7,8 +7,13 @@ const image_input = {
-
-
+
+
+
+
+
`
@@ -46,6 +51,7 @@ const image_input = {
this.target.find('.edit_image').click(function (e) {
let io = get_interface(e.target);
io.overlay_target.removeClass("hide");
+ io.target.find(".saliency_holder").addClass("hide");
})
this.tui_editor = new tui.ImageEditor(this.overlay_target.
find(".image_editor")[0], {
@@ -89,6 +95,24 @@ const image_input = {
this.target.find(".hidden_upload").prop("value", "")
this.state = "NO_IMAGE";
this.image_data = null;
+ this.target.find(".saliency_holder").addClass("hide");
+ },
+ output: function(data) {
+ if (this.target.find(".image_preview").attr("src")) {
+ var image = this.target.find(".image_preview");
+ this.target.find(".saliency_holder").removeClass("hide");
+ html = '';
+ data.forEach(function(row) {
+ html += ""
+ row.forEach(function(cell) {
+ opacity = cell > 0.3 ? cell : 0;
+ html += `
`
+ })
+ html += "
"
+ })
+ this.target.find(".saliency").width(
+ image.width()).height(image.height()).html(html)
+ }
},
state: "NO_IMAGE",
image_data: null,
diff --git a/gradio/static/js/vendor/heatmap.min.js b/gradio/static/js/vendor/heatmap.min.js
new file mode 100644
index 0000000000..e29f49172a
--- /dev/null
+++ b/gradio/static/js/vendor/heatmap.min.js
@@ -0,0 +1,9 @@
+/*
+ * heatmapjs v2.0.2 | JavaScript Heatmap Library
+ *
+ * Copyright 2008-2014 Patrick Wied - All rights reserved.
+ * Dual licensed under MIT and Beerware license
+ *
+ * :: 2016-02-03 23:49
+ */
+(function(a,b,c){if(typeof module!=="undefined"&&module.exports){module.exports=c()}else if(typeof define==="function"&&define.amd){define(c)}else{b[a]=c()}})("h337",this,function(){var a={defaultRadius:40,defaultRenderer:"canvas2d",defaultGradient:{.25:"rgb(0,0,255)",.55:"rgb(0,255,0)",.85:"yellow",1:"rgb(255,0,0)"},defaultMaxOpacity:1,defaultMinOpacity:0,defaultBlur:.85,defaultXField:"x",defaultYField:"y",defaultValueField:"value",plugins:{}};var b=function h(){var b=function d(a){this._coordinator={};this._data=[];this._radi=[];this._min=0;this._max=1;this._xField=a["xField"]||a.defaultXField;this._yField=a["yField"]||a.defaultYField;this._valueField=a["valueField"]||a.defaultValueField;if(a["radius"]){this._cfgRadius=a["radius"]}};var c=a.defaultRadius;b.prototype={_organiseData:function(a,b){var d=a[this._xField];var e=a[this._yField];var f=this._radi;var g=this._data;var h=this._max;var i=this._min;var j=a[this._valueField]||1;var k=a.radius||this._cfgRadius||c;if(!g[d]){g[d]=[];f[d]=[]}if(!g[d][e]){g[d][e]=j;f[d][e]=k}else{g[d][e]+=j}if(g[d][e]>h){if(!b){this._max=g[d][e]}else{this.setDataMax(g[d][e])}return false}else{return{x:d,y:e,value:j,radius:k,min:i,max:h}}},_unOrganizeData:function(){var a=[];var b=this._data;var c=this._radi;for(var d in b){for(var e in b[d]){a.push({x:d,y:e,radius:c[d][e],value:b[d][e]})}}return{min:this._min,max:this._max,data:a}},_onExtremaChange:function(){this._coordinator.emit("extremachange",{min:this._min,max:this._max})},addData:function(){if(arguments[0].length>0){var a=arguments[0];var b=a.length;while(b--){this.addData.call(this,a[b])}}else{var c=this._organiseData(arguments[0],true);if(c){this._coordinator.emit("renderpartial",{min:this._min,max:this._max,data:[c]})}}return this},setData:function(a){var b=a.data;var c=b.length;this._data=[];this._radi=[];for(var d=0;dthis._renderBoundaries[2]){this._renderBoundaries[2]=l+2*j}if(m+2*j>this._renderBoundaries[3]){this._renderBoundaries[3]=m+2*j}}},_colorize:function(){var a=this._renderBoundaries[0];var b=this._renderBoundaries[1];var c=this._renderBoundaries[2]-a;var d=this._renderBoundaries[3]-b;var e=this._width;var f=this._height;var g=this._opacity;var h=this._maxOpacity;var i=this._minOpacity;var j=this._useGradientOpacity;if(a<0){a=0}if(b<0){b=0}if(a+c>e){c=e-a}if(b+d>f){d=f-b}var k=this.shadowCtx.getImageData(a,b,c,d);var l=k.data;var m=l.length;var n=this._palette;for(var o=3;o0){r=g}else{if(p>0;return b},getDataURL:function(){return this.canvas.toDataURL()}};return d}();var d=function j(){var b=false;if(a["defaultRenderer"]==="canvas2d"){b=c}return b}();var e={merge:function(){var a={};var b=arguments.length;for(var c=0;c
+