mirror of
https://github.com/gradio-app/gradio.git
synced 2025-03-07 11:46:51 +08:00
unify post action
This commit is contained in:
parent
93731b850e
commit
0e49cfeabd
@ -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();
|
||||
})
|
||||
}
|
||||
};
|
||||
|
@ -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',
|
||||
|
@ -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');
|
||||
|
@ -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();
|
||||
})
|
||||
}
|
||||
};
|
||||
|
@ -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',
|
||||
|
@ -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');
|
||||
|
Loading…
Reference in New Issue
Block a user