mirror of
https://github.com/gradio-app/gradio.git
synced 2024-11-21 01:01:05 +08:00
multiple io/fn
This commit is contained in:
parent
a3bf3a1725
commit
1aa13a644d
@ -58,6 +58,9 @@ class Interface:
|
||||
self.output_interfaces = [get_output_instance(i) for i in outputs]
|
||||
else:
|
||||
self.output_interfaces = [get_output_instance(outputs)]
|
||||
if not isinstance(fn, list):
|
||||
fn = [fn]
|
||||
self.output_interfaces *= len(fn)
|
||||
self.predict = fn
|
||||
self.verbose = verbose
|
||||
self.status = "OFF"
|
||||
@ -71,6 +74,7 @@ class Interface:
|
||||
config = {
|
||||
"input_interfaces": [iface.__class__.__name__.lower() for iface in self.input_interfaces],
|
||||
"output_interfaces": [iface.__class__.__name__.lower() for iface in self.output_interfaces],
|
||||
"function_count": len(self.predict),
|
||||
"live": self.live,
|
||||
"show_input": self.show_input,
|
||||
"show_output": self.show_output,
|
||||
|
@ -137,10 +137,14 @@ def serve_files_in_background(interface, port, directory_to_serve=None):
|
||||
msg = json.loads(data_string)
|
||||
raw_input = msg["data"]
|
||||
processed_input = [input_interface.preprocess(raw_input[i]) for i, input_interface in enumerate(interface.input_interfaces)]
|
||||
prediction = interface.predict(*processed_input)
|
||||
if len(interface.input_interfaces) == 1:
|
||||
prediction = [prediction]
|
||||
processed_output = [output_interface.postprocess(prediction[i]) for i, output_interface in enumerate(interface.output_interfaces)]
|
||||
predictions = []
|
||||
for predict_fn in interface.predict:
|
||||
prediction = predict_fn(*processed_input)
|
||||
if len(interface.output_interfaces) == 1:
|
||||
prediction = [prediction]
|
||||
predictions.extend(prediction)
|
||||
print(predictions)
|
||||
processed_output = [output_interface.postprocess(predictions[i]) for i, output_interface in enumerate(interface.output_interfaces)]
|
||||
output = {"action": "output", "data": processed_output}
|
||||
if interface.saliency is not None:
|
||||
import numpy as np
|
||||
|
@ -12,15 +12,17 @@
|
||||
text-transform: uppercase;
|
||||
font-family: Arial;
|
||||
color: #888;
|
||||
padding: 6px;
|
||||
padding: 6px 6px 0;
|
||||
font-size: 14px;
|
||||
font-weight: bold;
|
||||
display: flex;
|
||||
}
|
||||
.input_interfaces, .output_interfaces {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.interface {
|
||||
height: 360px;
|
||||
margin-bottom: 16px;
|
||||
padding: 0 6px 6px;
|
||||
padding: 8px;
|
||||
display: flex;
|
||||
flex-flow: column;
|
||||
}
|
||||
@ -33,6 +35,10 @@
|
||||
}
|
||||
.panel_buttons {
|
||||
display: flex;
|
||||
margin-left: -8px;
|
||||
}
|
||||
.panel_buttons > * {
|
||||
margin-left: 8px;
|
||||
}
|
||||
.submit {
|
||||
display: none;
|
||||
@ -58,9 +64,6 @@
|
||||
padding: 8px !important;
|
||||
background-color: #EEEEEE !important;
|
||||
}
|
||||
.clear, .flag {
|
||||
margin-left: 8px;
|
||||
}
|
||||
|
||||
.upload_zone {
|
||||
font-weight: bold;
|
||||
|
@ -41,6 +41,9 @@ $.getJSON("static/config.json", function(data) {
|
||||
_id++;
|
||||
}
|
||||
for (let i = 0; i < config["output_interfaces"].length; i++) {
|
||||
if (i != 0 && i % (config["output_interfaces"].length / config.function_count) == 0) {
|
||||
$(".output_interfaces").append("<hr>");
|
||||
}
|
||||
output_interface = Object.create(output_to_object_map[
|
||||
config["output_interfaces"][i]]);
|
||||
$(".output_interfaces").append(`
|
||||
|
@ -1,7 +1,14 @@
|
||||
import gradio as gr
|
||||
import numpy as np
|
||||
from time import time
|
||||
|
||||
def flip(image):
|
||||
return np.flipud(image)
|
||||
start = time()
|
||||
return np.flipud(image), time() - start
|
||||
|
||||
gr.Interface(flip, "imagein", "image").launch()
|
||||
def flip2(image):
|
||||
start = time()
|
||||
return np.fliplr(image), time() - start
|
||||
|
||||
|
||||
gr.Interface([flip, flip2], "imagein", ["image", "textbox"]).launch()
|
BIN
dist/gradio-0.9.0-py3.7.egg
vendored
BIN
dist/gradio-0.9.0-py3.7.egg
vendored
Binary file not shown.
@ -58,6 +58,9 @@ class Interface:
|
||||
self.output_interfaces = [get_output_instance(i) for i in outputs]
|
||||
else:
|
||||
self.output_interfaces = [get_output_instance(outputs)]
|
||||
if not isinstance(fn, list):
|
||||
fn = [fn]
|
||||
self.output_interfaces *= len(fn)
|
||||
self.predict = fn
|
||||
self.verbose = verbose
|
||||
self.status = "OFF"
|
||||
@ -71,6 +74,7 @@ class Interface:
|
||||
config = {
|
||||
"input_interfaces": [iface.__class__.__name__.lower() for iface in self.input_interfaces],
|
||||
"output_interfaces": [iface.__class__.__name__.lower() for iface in self.output_interfaces],
|
||||
"function_count": len(self.predict),
|
||||
"live": self.live,
|
||||
"show_input": self.show_input,
|
||||
"show_output": self.show_output,
|
||||
|
@ -137,10 +137,14 @@ def serve_files_in_background(interface, port, directory_to_serve=None):
|
||||
msg = json.loads(data_string)
|
||||
raw_input = msg["data"]
|
||||
processed_input = [input_interface.preprocess(raw_input[i]) for i, input_interface in enumerate(interface.input_interfaces)]
|
||||
prediction = interface.predict(*processed_input)
|
||||
if len(interface.input_interfaces) == 1:
|
||||
prediction = [prediction]
|
||||
processed_output = [output_interface.postprocess(prediction[i]) for i, output_interface in enumerate(interface.output_interfaces)]
|
||||
predictions = []
|
||||
for predict_fn in interface.predict:
|
||||
prediction = predict_fn(*processed_input)
|
||||
if len(interface.output_interfaces) == 1:
|
||||
prediction = [prediction]
|
||||
predictions.extend(prediction)
|
||||
print(predictions)
|
||||
processed_output = [output_interface.postprocess(predictions[i]) for i, output_interface in enumerate(interface.output_interfaces)]
|
||||
output = {"action": "output", "data": processed_output}
|
||||
if interface.saliency is not None:
|
||||
import numpy as np
|
||||
|
@ -12,15 +12,17 @@
|
||||
text-transform: uppercase;
|
||||
font-family: Arial;
|
||||
color: #888;
|
||||
padding: 6px;
|
||||
padding: 6px 6px 0;
|
||||
font-size: 14px;
|
||||
font-weight: bold;
|
||||
display: flex;
|
||||
}
|
||||
.input_interfaces, .output_interfaces {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.interface {
|
||||
height: 360px;
|
||||
margin-bottom: 16px;
|
||||
padding: 0 6px 6px;
|
||||
padding: 8px;
|
||||
display: flex;
|
||||
flex-flow: column;
|
||||
}
|
||||
@ -33,6 +35,10 @@
|
||||
}
|
||||
.panel_buttons {
|
||||
display: flex;
|
||||
margin-left: -8px;
|
||||
}
|
||||
.panel_buttons > * {
|
||||
margin-left: 8px;
|
||||
}
|
||||
.submit {
|
||||
display: none;
|
||||
@ -58,9 +64,6 @@
|
||||
padding: 8px !important;
|
||||
background-color: #EEEEEE !important;
|
||||
}
|
||||
.clear, .flag {
|
||||
margin-left: 8px;
|
||||
}
|
||||
|
||||
.upload_zone {
|
||||
font-weight: bold;
|
||||
|
@ -41,6 +41,9 @@ $.getJSON("static/config.json", function(data) {
|
||||
_id++;
|
||||
}
|
||||
for (let i = 0; i < config["output_interfaces"].length; i++) {
|
||||
if (i != 0 && i % (config["output_interfaces"].length / config.function_count) == 0) {
|
||||
$(".output_interfaces").append("<hr>");
|
||||
}
|
||||
output_interface = Object.create(output_to_object_map[
|
||||
config["output_interfaces"][i]]);
|
||||
$(".output_interfaces").append(`
|
||||
|
Loading…
Reference in New Issue
Block a user