mirror of
https://github.com/gradio-app/gradio.git
synced 2025-02-17 11:29:58 +08:00
added latency
This commit is contained in:
parent
26a24b76d0
commit
a7723643ab
@ -105,7 +105,9 @@ class Interface:
|
||||
raw_input[i]) for i, input_interface in
|
||||
enumerate(self.input_interfaces)]
|
||||
predictions = []
|
||||
durations = []
|
||||
for predict_fn in self.predict:
|
||||
start = time.time()
|
||||
if self.capture_session:
|
||||
graph, sess = self.session
|
||||
with graph.as_default():
|
||||
@ -125,14 +127,16 @@ class Interface:
|
||||
"error.")
|
||||
else:
|
||||
raise exception
|
||||
duration = time.time() - start
|
||||
|
||||
if len(self.output_interfaces) / \
|
||||
len(self.predict) == 1:
|
||||
prediction = [prediction]
|
||||
durations.append(duration)
|
||||
predictions.extend(prediction)
|
||||
processed_output = [output_interface.postprocess(
|
||||
predictions[i]) for i, output_interface in enumerate(self.output_interfaces)]
|
||||
return processed_output
|
||||
return processed_output, durations
|
||||
|
||||
def validate(self):
|
||||
if self.validate_flag:
|
||||
|
@ -139,7 +139,9 @@ def serve_files_in_background(interface, port, directory_to_serve=None, server_n
|
||||
int(self.headers["Content-Length"]))
|
||||
msg = json.loads(data_string)
|
||||
raw_input = msg["data"]
|
||||
output = {"data": interface.process(raw_input)}
|
||||
prediction, durations = interface.process(raw_input)
|
||||
|
||||
output = {"data": prediction, "durations": durations}
|
||||
if interface.saliency is not None:
|
||||
saliency = interface.saliency(raw_input, prediction)
|
||||
output['saliency'] = saliency.tolist()
|
||||
|
@ -13,6 +13,14 @@ button, input[type="submit"], input[type="reset"], input[type="text"], input[typ
|
||||
-webkit-appearance: none;
|
||||
border-radius: 0;
|
||||
}
|
||||
|
||||
.loading_time {
|
||||
font-size: large;
|
||||
color: #EEA45D;
|
||||
text-align: right;
|
||||
padding-top: 5px;
|
||||
}
|
||||
|
||||
nav {
|
||||
text-align: center;
|
||||
padding: 16px 0 4px;
|
||||
|
@ -32,16 +32,18 @@ var io_master_template = {
|
||||
this.target.find(".loading_failed").show();
|
||||
})
|
||||
},
|
||||
output: function(data) {
|
||||
output: function(data) {
|
||||
this.last_output = data["data"];
|
||||
|
||||
for (let i = 0; i < this.output_interfaces.length; i++) {
|
||||
this.output_interfaces[i].output(data["data"][i]);
|
||||
this.output_interfaces[i].target.parent().find(`.loading_time[interface="${i}"]`).text("Latency: " + ((data["durations"][i])).toFixed(2) + "s");
|
||||
}
|
||||
if (this.config.live) {
|
||||
this.gather();
|
||||
} else {
|
||||
this.target.find(".loading").addClass("invisible");
|
||||
this.target.find(".output_interface").removeClass("invisible");
|
||||
this.target.find(".output_interface").removeClass("invisible");
|
||||
this.target.find(".output_interfaces .panel_header").removeClass("invisible");
|
||||
}
|
||||
},
|
||||
|
@ -91,6 +91,9 @@ function gradio(config, fn, target) {
|
||||
${output_interface.html}
|
||||
</div>
|
||||
`);
|
||||
target.find(".output_interfaces").append(`
|
||||
<div class="loading_time" interface="${i}"> </div>
|
||||
`);
|
||||
output_interface.target = target.find(`.output_interface[interface_id=${_id}]`);
|
||||
set_interface_id(output_interface, _id);
|
||||
output_interface.io_master = io_master;
|
||||
@ -110,6 +113,7 @@ function gradio(config, fn, target) {
|
||||
target.find(".flag").removeClass("flagged");
|
||||
target.find(".flag_message").empty();
|
||||
target.find(".loading").addClass("invisible");
|
||||
target.find(".loading_time").text("");
|
||||
target.find(".output_interface").removeClass("invisible");
|
||||
io_master.last_input = null;
|
||||
io_master.last_output = null;
|
||||
|
Loading…
Reference in New Issue
Block a user