This commit is contained in:
Ali Abid 2020-11-16 06:54:51 -08:00
parent abda96bf30
commit 9e20377204
4 changed files with 41 additions and 21 deletions

File diff suppressed because one or more lines are too long

View File

@ -3,6 +3,7 @@ README.md
setup.py setup.py
gradio/__init__.py gradio/__init__.py
gradio/component.py gradio/component.py
gradio/embeddings.py
gradio/inputs.py gradio/inputs.py
gradio/interface.py gradio/interface.py
gradio/interpretation.py gradio/interpretation.py

View File

@ -38,35 +38,18 @@ var io_master_template = {
this.target.find(".loading_failed").show(); this.target.find(".loading_failed").show();
}); });
}, },
score_similarity: function() { score_similarity: function(callback) {
this.target.find(".loading").removeClass("invisible"); this.target.find(".loading").removeClass("invisible");
this.target.find(".loading_in_progress").show(); this.target.find(".loading_in_progress").show();
this.target.find(".loading_failed").hide(); this.target.find(".loading_failed").hide();
this.target.find(".output_interfaces").css("opacity", 0.5); this.target.find(".output_interfaces").css("opacity", 0.5);
this.fn(this.last_input, "score_similarity").then((output) => { this.fn(this.last_input, "score_similarity").then((output) => {
output = output["data"];
this.target.find(".loading").addClass("invisible"); this.target.find(".loading").addClass("invisible");
this.target.find(".output_interfaces").css("opacity", 1); this.target.find(".output_interfaces").css("opacity", 1);
let html = "<th>SIMILARITY</th>" this.order_mapping = sortWithIndices(output);
this.target.find(".examples > table > thead > tr").append(html); callback();
for (let i = 0; i < output["data"].length; i++) {
let html = "<td>" + output["data"][i] + "</td>"
this.target.find(".examples_body tr[row='" + i + "']").append(html);
}
function getCellValue(row, index){ return $(row).children('td').eq(index).text() }
function comparer(index) {
return function(a, b) {
var valA = getCellValue(a, index), valB = getCellValue(b, index)
return $.isNumeric(valA) && $.isNumeric(valB) ? valA - valB : valA.toString().localeCompare(valB)
}
}
var table = $(".examples > table").eq(0)
var rows = table.find('tr:gt(0)').toArray().sort(comparer(-1)).reverse() // sort by last column
table.find("tr:gt(0)").remove()
for (var i = 0; i < rows.length; i++){table.append(rows[i]); console.log(i)}
}) })
}, },
submit_examples: function() { submit_examples: function() {

View File

@ -6,6 +6,21 @@ String.prototype.format = function() {
return a return a
} }
function sortWithIndices(toSort) {
for (var i = 0; i < toSort.length; i++) {
toSort[i] = [toSort[i], i];
}
toSort.sort(function(left, right) {
return left[0] < right[0] ? -1 : 1;
});
toSort.sortIndices = [];
for (var j = 0; j < toSort.length; j++) {
toSort.sortIndices.push(toSort[j][1]);
toSort[j] = toSort[j][0];
}
return toSort.sortIndices;
}
function toDataURL(url, callback) { function toDataURL(url, callback) {
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
xhr.onload = function() { xhr.onload = function() {