mirror of
https://github.com/gradio-app/gradio.git
synced 2025-01-30 11:00:11 +08:00
Merge branch 'master' into aliabd/saliency
This commit is contained in:
commit
9b110611d7
@ -54,9 +54,9 @@ const sketchpad_input = {
|
||||
},
|
||||
output: function(data) {
|
||||
this.target.find(".saliency_holder").removeClass("hide");
|
||||
var ctx = this.target.find(".saliency")[0].getContext('2d');
|
||||
let ctx = this.target.find(".saliency")[0].getContext('2d');
|
||||
let dimension = this.target.find(".saliency").width();
|
||||
console.log(data, dimension, dimension);
|
||||
ctx.clearRect(0,0,dimension,dimension);
|
||||
paintSaliency(data, dimension, dimension, ctx);
|
||||
},
|
||||
clear: function() {
|
||||
|
@ -16,7 +16,7 @@ const textbox_input = {
|
||||
let text = this.target.find(".input_text").val();
|
||||
let index = 0;
|
||||
data.forEach(function(value, index) {
|
||||
html += `<span style='background-color:rgba(255,0,0,${value})'>${text.charAt(index)}</span>`;
|
||||
html += `<span style='background-color:rgba(0,0,255,${value})'>${text.charAt(index)}</span>`;
|
||||
})
|
||||
$(".input_text_saliency").html(html);
|
||||
},
|
||||
|
@ -47,15 +47,7 @@ function paintSaliency(data, width, height, ctx) {
|
||||
data.forEach(function(row) {
|
||||
var c = 0
|
||||
row.forEach(function(cell) {
|
||||
if (cell < 0.25) {
|
||||
ctx.fillStyle = "white";
|
||||
} else if (cell < 0.5) {
|
||||
ctx.fillStyle = "yellow";
|
||||
} else if (cell < 0.75) {
|
||||
ctx.fillStyle = "orange";
|
||||
} else {
|
||||
ctx.fillStyle = "red";
|
||||
}
|
||||
ctx.fillStyle = `rgba(${(1 - cell) * 255},${(1 - cell) * 255},255,0.5)`;
|
||||
ctx.fillRect(c * cell_width, r * cell_height, cell_width, cell_height);
|
||||
c++;
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user