mirror of
https://github.com/gradio-app/gradio.git
synced 2025-01-06 10:25:17 +08:00
screenshot flag
This commit is contained in:
parent
4dfec5539d
commit
9cfe8dd93a
@ -40,7 +40,8 @@ class Interface:
|
|||||||
def __init__(self, fn, inputs, outputs, saliency=None, verbose=False, examples=None,
|
def __init__(self, fn, inputs, outputs, saliency=None, verbose=False, examples=None,
|
||||||
live=False, show_input=True, show_output=True,
|
live=False, show_input=True, show_output=True,
|
||||||
capture_session=False, title=None, description=None,
|
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:
|
Parameters:
|
||||||
fn (Callable): the function to wrap an interface around.
|
fn (Callable): the function to wrap an interface around.
|
||||||
@ -99,6 +100,7 @@ class Interface:
|
|||||||
self.examples = examples
|
self.examples = examples
|
||||||
self.server_port = server_port
|
self.server_port = server_port
|
||||||
self.simple_server = None
|
self.simple_server = None
|
||||||
|
self.allow_screenshot = allow_screenshot
|
||||||
Interface.instances.add(self)
|
Interface.instances.add(self)
|
||||||
|
|
||||||
data = {'fn': fn,
|
data = {'fn': fn,
|
||||||
@ -138,7 +140,8 @@ class Interface:
|
|||||||
"show_output": self.show_output,
|
"show_output": self.show_output,
|
||||||
"title": self.title,
|
"title": self.title,
|
||||||
"description": self.description,
|
"description": self.description,
|
||||||
"thumbnail": self.thumbnail
|
"thumbnail": self.thumbnail,
|
||||||
|
"allow_screenshot": self.allow_screenshot
|
||||||
}
|
}
|
||||||
try:
|
try:
|
||||||
param_names = inspect.getfullargspec(self.predict[0])[0]
|
param_names = inspect.getfullargspec(self.predict[0])[0]
|
||||||
|
@ -97,3 +97,6 @@ input.submit:hover {
|
|||||||
.invisible {
|
.invisible {
|
||||||
display: none !important;
|
display: none !important;
|
||||||
}
|
}
|
||||||
|
.screenshot {
|
||||||
|
visibility: hidden;
|
||||||
|
}
|
@ -2,7 +2,6 @@
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
font-size: 18px;
|
font-size: 18px;
|
||||||
outline: none;
|
outline: none;
|
||||||
height: 100%;
|
|
||||||
background-color: white;
|
background-color: white;
|
||||||
border: solid 1px lightgray;
|
border: solid 1px lightgray;
|
||||||
border-radius: 2px;
|
border-radius: 2px;
|
||||||
|
@ -18,7 +18,7 @@ function gradio(config, fn, target) {
|
|||||||
<div class="output_interfaces">
|
<div class="output_interfaces">
|
||||||
</div>
|
</div>
|
||||||
<div class="panel_buttons">
|
<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>
|
</div>
|
||||||
</div>`);
|
</div>`);
|
||||||
@ -121,6 +121,9 @@ function gradio(config, fn, target) {
|
|||||||
io_master.last_input = null;
|
io_master.last_input = null;
|
||||||
io_master.last_output = null;
|
io_master.last_output = null;
|
||||||
});
|
});
|
||||||
|
if (config["allow_screenshot"]) {
|
||||||
|
target.find(".screenshot").css("visibility", "visible");
|
||||||
|
}
|
||||||
target.find(".screenshot").click(function() {
|
target.find(".screenshot").click(function() {
|
||||||
html2canvas(target[0]).then(function(canvas) {
|
html2canvas(target[0]).then(function(canvas) {
|
||||||
saveAs(canvas.toDataURL(), 'screenshot.png');
|
saveAs(canvas.toDataURL(), 'screenshot.png');
|
||||||
|
@ -40,7 +40,8 @@ class Interface:
|
|||||||
def __init__(self, fn, inputs, outputs, saliency=None, verbose=False, examples=None,
|
def __init__(self, fn, inputs, outputs, saliency=None, verbose=False, examples=None,
|
||||||
live=False, show_input=True, show_output=True,
|
live=False, show_input=True, show_output=True,
|
||||||
capture_session=False, title=None, description=None,
|
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:
|
Parameters:
|
||||||
fn (Callable): the function to wrap an interface around.
|
fn (Callable): the function to wrap an interface around.
|
||||||
@ -99,6 +100,7 @@ class Interface:
|
|||||||
self.examples = examples
|
self.examples = examples
|
||||||
self.server_port = server_port
|
self.server_port = server_port
|
||||||
self.simple_server = None
|
self.simple_server = None
|
||||||
|
self.allow_screenshot = allow_screenshot
|
||||||
Interface.instances.add(self)
|
Interface.instances.add(self)
|
||||||
|
|
||||||
data = {'fn': fn,
|
data = {'fn': fn,
|
||||||
@ -138,7 +140,8 @@ class Interface:
|
|||||||
"show_output": self.show_output,
|
"show_output": self.show_output,
|
||||||
"title": self.title,
|
"title": self.title,
|
||||||
"description": self.description,
|
"description": self.description,
|
||||||
"thumbnail": self.thumbnail
|
"thumbnail": self.thumbnail,
|
||||||
|
"allow_screenshot": self.allow_screenshot
|
||||||
}
|
}
|
||||||
try:
|
try:
|
||||||
param_names = inspect.getfullargspec(self.predict[0])[0]
|
param_names = inspect.getfullargspec(self.predict[0])[0]
|
||||||
|
@ -97,3 +97,6 @@ input.submit:hover {
|
|||||||
.invisible {
|
.invisible {
|
||||||
display: none !important;
|
display: none !important;
|
||||||
}
|
}
|
||||||
|
.screenshot {
|
||||||
|
visibility: hidden;
|
||||||
|
}
|
@ -2,7 +2,6 @@
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
font-size: 18px;
|
font-size: 18px;
|
||||||
outline: none;
|
outline: none;
|
||||||
height: 100%;
|
|
||||||
background-color: white;
|
background-color: white;
|
||||||
border: solid 1px lightgray;
|
border: solid 1px lightgray;
|
||||||
border-radius: 2px;
|
border-radius: 2px;
|
||||||
|
@ -18,7 +18,7 @@ function gradio(config, fn, target) {
|
|||||||
<div class="output_interfaces">
|
<div class="output_interfaces">
|
||||||
</div>
|
</div>
|
||||||
<div class="panel_buttons">
|
<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>
|
</div>
|
||||||
</div>`);
|
</div>`);
|
||||||
@ -121,6 +121,9 @@ function gradio(config, fn, target) {
|
|||||||
io_master.last_input = null;
|
io_master.last_input = null;
|
||||||
io_master.last_output = null;
|
io_master.last_output = null;
|
||||||
});
|
});
|
||||||
|
if (config["allow_screenshot"]) {
|
||||||
|
target.find(".screenshot").css("visibility", "visible");
|
||||||
|
}
|
||||||
target.find(".screenshot").click(function() {
|
target.find(".screenshot").click(function() {
|
||||||
html2canvas(target[0]).then(function(canvas) {
|
html2canvas(target[0]).then(function(canvas) {
|
||||||
saveAs(canvas.toDataURL(), 'screenshot.png');
|
saveAs(canvas.toDataURL(), 'screenshot.png');
|
||||||
|
Loading…
Reference in New Issue
Block a user