screenshot flag

This commit is contained in:
Ali Abid 2020-07-20 08:59:19 -07:00
parent 4dfec5539d
commit 9cfe8dd93a
8 changed files with 24 additions and 8 deletions

View File

@ -40,7 +40,8 @@ class Interface:
def __init__(self, fn, inputs, outputs, saliency=None, verbose=False, examples=None,
live=False, show_input=True, show_output=True,
capture_session=False, title=None, description=None,
thumbnail=None, server_port=None, server_name=networking.LOCALHOST_NAME):
thumbnail=None, server_port=None, server_name=networking.LOCALHOST_NAME,
allow_screenshot=True):
"""
Parameters:
fn (Callable): the function to wrap an interface around.
@ -99,6 +100,7 @@ class Interface:
self.examples = examples
self.server_port = server_port
self.simple_server = None
self.allow_screenshot = allow_screenshot
Interface.instances.add(self)
data = {'fn': fn,
@ -138,7 +140,8 @@ class Interface:
"show_output": self.show_output,
"title": self.title,
"description": self.description,
"thumbnail": self.thumbnail
"thumbnail": self.thumbnail,
"allow_screenshot": self.allow_screenshot
}
try:
param_names = inspect.getfullargspec(self.predict[0])[0]

View File

@ -97,3 +97,6 @@ input.submit:hover {
.invisible {
display: none !important;
}
.screenshot {
visibility: hidden;
}

View File

@ -2,7 +2,6 @@
width: 100%;
font-size: 18px;
outline: none;
height: 100%;
background-color: white;
border: solid 1px lightgray;
border-radius: 2px;

View File

@ -18,7 +18,7 @@ function gradio(config, fn, target) {
<div class="output_interfaces">
</div>
<div class="panel_buttons">
<input class="screenshot panel_button" type="button" value="SCREENSHOT" style="visibility: hidden"/>
<input class="screenshot panel_button" type="button" value="SCREENSHOT"/>
</div>
</div>
</div>`);
@ -121,6 +121,9 @@ function gradio(config, fn, target) {
io_master.last_input = null;
io_master.last_output = null;
});
if (config["allow_screenshot"]) {
target.find(".screenshot").css("visibility", "visible");
}
target.find(".screenshot").click(function() {
html2canvas(target[0]).then(function(canvas) {
saveAs(canvas.toDataURL(), 'screenshot.png');

View File

@ -40,7 +40,8 @@ class Interface:
def __init__(self, fn, inputs, outputs, saliency=None, verbose=False, examples=None,
live=False, show_input=True, show_output=True,
capture_session=False, title=None, description=None,
thumbnail=None, server_port=None, server_name=networking.LOCALHOST_NAME):
thumbnail=None, server_port=None, server_name=networking.LOCALHOST_NAME,
allow_screenshot=True):
"""
Parameters:
fn (Callable): the function to wrap an interface around.
@ -99,6 +100,7 @@ class Interface:
self.examples = examples
self.server_port = server_port
self.simple_server = None
self.allow_screenshot = allow_screenshot
Interface.instances.add(self)
data = {'fn': fn,
@ -138,7 +140,8 @@ class Interface:
"show_output": self.show_output,
"title": self.title,
"description": self.description,
"thumbnail": self.thumbnail
"thumbnail": self.thumbnail,
"allow_screenshot": self.allow_screenshot
}
try:
param_names = inspect.getfullargspec(self.predict[0])[0]

View File

@ -97,3 +97,6 @@ input.submit:hover {
.invisible {
display: none !important;
}
.screenshot {
visibility: hidden;
}

View File

@ -2,7 +2,6 @@
width: 100%;
font-size: 18px;
outline: none;
height: 100%;
background-color: white;
border: solid 1px lightgray;
border-radius: 2px;

View File

@ -18,7 +18,7 @@ function gradio(config, fn, target) {
<div class="output_interfaces">
</div>
<div class="panel_buttons">
<input class="screenshot panel_button" type="button" value="SCREENSHOT" style="visibility: hidden"/>
<input class="screenshot panel_button" type="button" value="SCREENSHOT"/>
</div>
</div>
</div>`);
@ -121,6 +121,9 @@ function gradio(config, fn, target) {
io_master.last_input = null;
io_master.last_output = null;
});
if (config["allow_screenshot"]) {
target.find(".screenshot").css("visibility", "visible");
}
target.find(".screenshot").click(function() {
html2canvas(target[0]).then(function(canvas) {
saveAs(canvas.toDataURL(), 'screenshot.png');