diff --git a/gradio/static/css/interfaces/input/sketchpad.css b/gradio/static/css/interfaces/input/sketchpad.css index 651a7f0721..de8d9064b6 100644 --- a/gradio/static/css/interfaces/input/sketchpad.css +++ b/gradio/static/css/interfaces/input/sketchpad.css @@ -45,7 +45,7 @@ .saliency_holder { position: absolute; top: 0; - opacity: 0.7; + opacity: 0.9; } .view_holders canvas { background-color: white; diff --git a/gradio/static/js/interfaces/input/textbox.js b/gradio/static/js/interfaces/input/textbox.js index fe30437795..c3c5b13bf9 100644 --- a/gradio/static/js/interfaces/input/textbox.js +++ b/gradio/static/js/interfaces/input/textbox.js @@ -16,7 +16,7 @@ const textbox_input = { let text = this.target.find(".input_text").val(); let index = 0; data.forEach(function(value, index) { - html += `${text.charAt(index)}`; + html += `${text.charAt(index)}`; }) $(".input_text_saliency").html(html); }, diff --git a/gradio/static/js/utils.js b/gradio/static/js/utils.js index 64d81ea280..3a55f5955c 100644 --- a/gradio/static/js/utils.js +++ b/gradio/static/js/utils.js @@ -44,13 +44,32 @@ function paintSaliency(data, width, height, ctx) { var cell_width = width / data[0].length var cell_height = height / data.length var r = 0 + let blue = [75, 150, 255]; + let white = [255, 255, 255]; data.forEach(function(row) { var c = 0 row.forEach(function(cell) { - ctx.fillStyle = `rgba(${(1 - cell) * 255},${(1 - cell) * 255},255,0.5)`; + let shade = interpolate(cell, blue, white) + ctx.fillStyle = colorToString(shade); ctx.fillRect(c * cell_width, r * cell_height, cell_width, cell_height); c++; }) r++; }) } + +// val should be in the range [0.0, 1.0] +// rgb1 and rgb2 should be an array of 3 values each in the range [0, 255] +function interpolate(val, rgb1, rgb2) { + var rgb = [0,0,0]; + var i; + for (i = 0; i < 3; i++) { + rgb[i] = rgb1[i] * (1.0 - val) + rgb2[i] * val; + } + return rgb; +} + +// quick helper function to convert the array into something we can use for css +function colorToString(rgb) { + return "rgb(" + rgb[0] + ", " + rgb[1] + ", " + rgb[2] + ")"; +}