unify post action

This commit is contained in:
Ali Abid 2020-09-24 13:06:09 -07:00
parent 93731b850e
commit 0e49cfeabd
6 changed files with 36 additions and 58 deletions

View File

@ -29,7 +29,7 @@ var io_master_template = {
this.target.find(".loading_failed").hide();
this.target.find(".output_interfaces").css("opacity", 0.5);
}
this.fn(this.last_input).then((output) => {
this.fn(this.last_input, "predict").then((output) => {
io.output(output);
}).catch((error) => {
console.error(error);
@ -72,36 +72,25 @@ var io_master_template = {
},
flag: function() {
var post_data = {
'data': {
'input_data' : this.last_input ,
'output_data' : this.last_output
}
'input_data' : this.last_input ,
'output_data' : this.last_output
}
$.ajax({type: "POST",
url: "/api/flag/",
data: JSON.stringify(post_data),
dataType: 'json',
contentType: 'application/json; charset=utf-8',
});
this.fn(post_data, "flag")
},
interpret: function() {
var io = this;
this.target.find(".loading").removeClass("invisible");
this.target.find(".loading_in_progress").show();
var post_data = {
'data': this.last_input
}
$.ajax({type: "POST",
url: "/api/interpret/",
data: JSON.stringify(post_data),
dataType: 'json',
contentType: 'application/json; charset=utf-8',
success: function(data) {
for (let [idx, interpretation] of data.entries()) {
io.input_interfaces[idx].show_interpretation(interpretation);
}
io.target.find(".loading_in_progress").hide();
}
});
var post_data = this.last_input;
this.fn(post_data, "interpret").then((data) => {
for (let [idx, interpretation] of data.entries()) {
io.input_interfaces[idx].show_interpretation(interpretation);
}
io.target.find(".loading_in_progress").hide();
}).catch((error) => {
console.error(error);
this.target.find(".loading_in_progress").hide();
this.target.find(".loading_failed").show();
})
}
};

View File

@ -250,10 +250,10 @@ function gradio(config, fn, target, example_file_path) {
return io_master;
}
function gradio_url(config, url, target, example_file_path) {
return gradio(config, function(data) {
return gradio(config, function(data, action) {
return new Promise((resolve, reject) => {
$.ajax({type: "POST",
url: url,
url: url + action,
data: JSON.stringify({"data": data}),
dataType: 'json',
contentType: 'application/json; charset=utf-8',

View File

@ -118,7 +118,7 @@
<script src="/static/js/gradio.js"></script>
<script>
$.getJSON("/config/", function(config) {
io = gradio_url(config, "/api/predict/", "#interface_target", "/file/");
io = gradio_url(config, "/api/", "#interface_target", "/file/");
});
const copyToClipboard = str => {
const el = document.createElement('textarea');

View File

@ -29,7 +29,7 @@ var io_master_template = {
this.target.find(".loading_failed").hide();
this.target.find(".output_interfaces").css("opacity", 0.5);
}
this.fn(this.last_input).then((output) => {
this.fn(this.last_input, "predict").then((output) => {
io.output(output);
}).catch((error) => {
console.error(error);
@ -72,36 +72,25 @@ var io_master_template = {
},
flag: function() {
var post_data = {
'data': {
'input_data' : this.last_input ,
'output_data' : this.last_output
}
'input_data' : this.last_input ,
'output_data' : this.last_output
}
$.ajax({type: "POST",
url: "/api/flag/",
data: JSON.stringify(post_data),
dataType: 'json',
contentType: 'application/json; charset=utf-8',
});
this.fn(post_data, "flag")
},
interpret: function() {
var io = this;
this.target.find(".loading").removeClass("invisible");
this.target.find(".loading_in_progress").show();
var post_data = {
'data': this.last_input
}
$.ajax({type: "POST",
url: "/api/interpret/",
data: JSON.stringify(post_data),
dataType: 'json',
contentType: 'application/json; charset=utf-8',
success: function(data) {
for (let [idx, interpretation] of data.entries()) {
io.input_interfaces[idx].show_interpretation(interpretation);
}
io.target.find(".loading_in_progress").hide();
}
});
var post_data = this.last_input;
this.fn(post_data, "interpret").then((data) => {
for (let [idx, interpretation] of data.entries()) {
io.input_interfaces[idx].show_interpretation(interpretation);
}
io.target.find(".loading_in_progress").hide();
}).catch((error) => {
console.error(error);
this.target.find(".loading_in_progress").hide();
this.target.find(".loading_failed").show();
})
}
};

View File

@ -250,10 +250,10 @@ function gradio(config, fn, target, example_file_path) {
return io_master;
}
function gradio_url(config, url, target, example_file_path) {
return gradio(config, function(data) {
return gradio(config, function(data, action) {
return new Promise((resolve, reject) => {
$.ajax({type: "POST",
url: url,
url: url + action,
data: JSON.stringify({"data": data}),
dataType: 'json',
contentType: 'application/json; charset=utf-8',

View File

@ -118,7 +118,7 @@
<script src="/static/js/gradio.js"></script>
<script>
$.getJSON("/config/", function(config) {
io = gradio_url(config, "/api/predict/", "#interface_target", "/file/");
io = gradio_url(config, "/api/", "#interface_target", "/file/");
});
const copyToClipboard = str => {
const el = document.createElement('textarea');