mirror of
https://github.com/gradio-app/gradio.git
synced 2025-03-07 11:46:51 +08:00
fixed auto tests
This commit is contained in:
parent
2edd1deda8
commit
be0556a8bc
@ -36,7 +36,7 @@
|
||||
.panel_buttons {
|
||||
display: flex;
|
||||
}
|
||||
.submit, .clear, .flag {
|
||||
.submit, .clear, .panel_button {
|
||||
background-color: #F6F6F6 !important;
|
||||
flex-grow: 1;
|
||||
padding: 8px !important;
|
||||
@ -107,3 +107,16 @@
|
||||
.flag.flagged {
|
||||
background-color: pink !important;
|
||||
}
|
||||
|
||||
.test_panel {
|
||||
margin-top: 5px;
|
||||
padding:10px;
|
||||
background-color: #eea45d6b !important;
|
||||
border: 1px solid #EEA45D;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.test_panel > input[type="button"] {
|
||||
max-width: 100px;
|
||||
}
|
||||
|
@ -27,6 +27,22 @@ var io_master = {
|
||||
this.input_interface.output(data["saliency"]);
|
||||
}
|
||||
},
|
||||
test: function(type, data) {
|
||||
var post_data = {
|
||||
'data': data
|
||||
};
|
||||
if (type == "rotation") {
|
||||
$.ajax({type: "POST",
|
||||
url: "/api/auto/rotation",
|
||||
data: JSON.stringify(post_data)
|
||||
});
|
||||
} else if (type == "lighting") {
|
||||
$.ajax({type: "POST",
|
||||
url: "/api/auto/lighting",
|
||||
data: JSON.stringify(post_data)
|
||||
});
|
||||
}
|
||||
},
|
||||
flag: function(message) {
|
||||
var post_data = {
|
||||
'data': {
|
||||
|
@ -25,11 +25,21 @@ const image_input = {
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
test_html: `
|
||||
<div class="panel_buttons test_panel">
|
||||
<div><strong>Rotation</strong>: (rotates between -180 and 180 degrees)</div>
|
||||
<input type="button" class="panel_button rotate_test" value="Run"/>
|
||||
</div>
|
||||
<div class="panel_buttons test_panel">
|
||||
<div><strong>Lighting</strong>: (adjusts the lighting to 9 different levels)</div>
|
||||
<input type="button" class="panel_button light_test" value="Run"/>
|
||||
</div>
|
||||
`,
|
||||
init: function() {
|
||||
var io = this;
|
||||
$('body').append(this.overlay_html.format(this.id));
|
||||
this.overlay_target = $(`.overlay[interface_id=${this.id}]`);
|
||||
this.target.find(".upload_zone").click(function (e) {
|
||||
let io = get_interface(e.target)
|
||||
io.target.find(".hidden_upload").click();
|
||||
});
|
||||
this.target.on('drag dragstart dragend dragover dragenter dragleave drop',
|
||||
@ -38,18 +48,15 @@ const image_input = {
|
||||
e.stopPropagation();
|
||||
})
|
||||
this.target.on('drop', '.drop_zone', function(e) {
|
||||
let io = get_interface(e.target)
|
||||
files = e.originalEvent.dataTransfer.files;
|
||||
io.load_preview_from_files(files)
|
||||
});
|
||||
this.target.find('.hidden_upload').on('change', function (e) {
|
||||
if (this.files) {
|
||||
let io = get_interface(e.target);
|
||||
io.load_preview_from_files(this.files);
|
||||
}
|
||||
})
|
||||
this.target.find('.edit_image').click(function (e) {
|
||||
let io = get_interface(e.target);
|
||||
io.overlay_target.removeClass("hide");
|
||||
io.target.find(".saliency_holder").addClass("hide");
|
||||
})
|
||||
@ -71,7 +78,6 @@ const image_input = {
|
||||
<button class="tui_cancel tui_close interface_button secondary">Cancel</button>
|
||||
`)
|
||||
this.overlay_target.find('.tui_close').click(function (e) {
|
||||
let io = get_interface(e.target);
|
||||
io.overlay_target.addClass("hide");
|
||||
if ($(e.target).hasClass('tui_save')) {
|
||||
// if (io.tui_editor.ui.submenu == "crop") {
|
||||
@ -80,6 +86,17 @@ const image_input = {
|
||||
io.set_image_data(io.tui_editor.toDataURL(), /*update_editor=*/false);
|
||||
}
|
||||
});
|
||||
$(".tests").html(this.test_html);
|
||||
$(".rotate_test").click(function () {
|
||||
if (io.image_data) {
|
||||
io.io_master.test("rotation", io.image_data);
|
||||
}
|
||||
})
|
||||
$(".light_test").click(function () {
|
||||
if (io.image_data) {
|
||||
io.io_master.test("lighting", io.image_data);
|
||||
}
|
||||
})
|
||||
},
|
||||
submit: function() {
|
||||
if (this.state == "IMAGE_LOADED") {
|
||||
|
@ -9,6 +9,7 @@ const sketchpad_input = {
|
||||
<canvas id="canvas"></canvas>
|
||||
</div>`,
|
||||
init: function() {
|
||||
var io = this;
|
||||
var dimension = Math.min(this.target.find(".canvas_holder").width(),
|
||||
this.target.find(".canvas_holder").height()) - 2 // dimension - border
|
||||
var id = this.id;
|
||||
@ -21,7 +22,6 @@ const sketchpad_input = {
|
||||
this.canvas = this.target.find('.canvas_holder canvas')[0];
|
||||
this.context = this.canvas.getContext("2d");
|
||||
this.target.find(".brush").click(function (e) {
|
||||
let io = get_interface(e.target)
|
||||
io.target.find(".brush").removeClass("selected");
|
||||
$(this).addClass("selected");
|
||||
io.sketchpad.penSize = $(this).attr("size");
|
||||
|
@ -19,11 +19,6 @@ function set_interface_id(interface, id) {
|
||||
interface.target.attr("interface_id", id);
|
||||
}
|
||||
|
||||
function get_interface(target) {
|
||||
return id_to_interface_map[$(target).closest(".interface, .interface_extension").
|
||||
attr("interface_id")];
|
||||
}
|
||||
|
||||
var config;
|
||||
$.getJSON("static/config.json", function(data) {
|
||||
config = data;
|
||||
|
@ -44,15 +44,7 @@
|
||||
<input class="submit" type="submit" value="submit"/>
|
||||
<input class="clear" type="reset" value="clear">
|
||||
</div>
|
||||
<!--TODO(aliabid94): can you set this up so that so this sends the image in the same payload as /api/predict-->
|
||||
<div class="panel_buttons" style="margin-bottom: 5px; padding:10px; background-color: #eea45d6b !important; border: 1px solid #EEA45D"">
|
||||
<strong>Rotation</strong>: (rotates between -180 and 180 degrees)<br>
|
||||
<input type="button" class="flag" style="width:30%" value="Run"/>
|
||||
</div>
|
||||
<div class="panel_buttons" style="margin-bottom: 5px; padding:10px; background-color: #eea45d6b !important; border: 1px solid #EEA45D"">
|
||||
<strong>Lighting</strong>: (adjusts the lighting to 9 different levels)<br>
|
||||
<input type="button" class="flag" style="width:30%" value="Run"/>
|
||||
</div>
|
||||
<div class="tests"></div>
|
||||
</div>
|
||||
<div class="panel">
|
||||
<div class="panel_header">
|
||||
@ -65,7 +57,7 @@
|
||||
<div id="output_interface" class="interface"></div>
|
||||
<div class="panel_buttons">
|
||||
<input type="text" class="flag_message" placeholder="(Optional message for flagging)"/>
|
||||
<input type="button" class="flag" value="flag"/>
|
||||
<input type="button" class="panel_button flag" value="flag"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user