mirror of
https://github.com/gradio-app/gradio.git
synced 2025-03-07 11:46:51 +08:00
remove-queue-from-events (#1056)
* remove-queue-from-events - enable_queue exists just under Blocks.launch() * remove-queue-from-events - enable_queue exists just under Blocks.launch() * remove-queue-from-events - fix tests * spaces-defaults (#1057) * spaces-defaults - enable_queue and cache_examples are activated in spaces in default option * spaces-defaults - tweaks
This commit is contained in:
parent
1ec62d969c
commit
72df62daea
@ -59,7 +59,6 @@ class Block:
|
||||
outputs: List[Component],
|
||||
preprocess: bool = True,
|
||||
postprocess: bool = True,
|
||||
queue=False,
|
||||
no_target: bool = False,
|
||||
status_tracker: Optional[StatusTracker] = None,
|
||||
) -> None:
|
||||
@ -72,7 +71,6 @@ class Block:
|
||||
outputs: output list
|
||||
preprocess: whether to run the preprocess methods of components
|
||||
postprocess: whether to run the postprocess methods of components
|
||||
queue: if True, will store multiple calls in queue and run in order instead of in parallel with multiple threads
|
||||
no_target: if True, sets "targets" to [], used for Blocks "load" event
|
||||
status_tracker: StatusTracker to visualize function progress
|
||||
Returns: None
|
||||
@ -90,7 +88,6 @@ class Block:
|
||||
"trigger": event_name,
|
||||
"inputs": [block._id for block in inputs],
|
||||
"outputs": [block._id for block in outputs],
|
||||
"queue": queue,
|
||||
"status_tracker": status_tracker._id
|
||||
if status_tracker is not None
|
||||
else None,
|
||||
@ -209,12 +206,11 @@ class Blocks(BlockContext):
|
||||
mode: str = "blocks",
|
||||
):
|
||||
|
||||
# Cleanup shared parameters with Interface
|
||||
# Cleanup shared parameters with Interface #TODO: is this part still necessary after Interface with Blocks?
|
||||
self.save_to = None
|
||||
self.api_mode = False
|
||||
self.theme = theme
|
||||
self.requires_permissions = False # TODO: needs to be implemented
|
||||
self.enable_queue = False
|
||||
|
||||
# For analytics_enabled and allow_flagging: (1) first check for
|
||||
# parameter, (2) check for env variable, (3) default to True/"manual"
|
||||
@ -378,7 +374,7 @@ class Blocks(BlockContext):
|
||||
server_name: Optional[str] = None,
|
||||
server_port: Optional[int] = None,
|
||||
show_tips: bool = False,
|
||||
enable_queue: bool = False,
|
||||
enable_queue: Optional[bool] = None,
|
||||
height: int = 500,
|
||||
width: int = 900,
|
||||
encrypt: bool = False,
|
||||
@ -402,7 +398,10 @@ class Blocks(BlockContext):
|
||||
server_port (int): will start gradio app on this port (if available). Can be set by environment variable GRADIO_SERVER_PORT.
|
||||
server_name (str): to make app accessible on local network, set this to "0.0.0.0". Can be set by environment variable GRADIO_SERVER_NAME.
|
||||
show_tips (bool): if True, will occasionally show tips about new Gradio features
|
||||
enable_queue (bool): if True, inference requests will be served through a queue instead of with parallel threads. Required for longer inference times (> 1min) to prevent timeout.
|
||||
enable_queue (Optional[bool]):
|
||||
if True, inference requests will be served through a queue instead of with parallel threads. Required for longer inference times (> 1min) to prevent timeout.
|
||||
The default option in HuggingFace Spaces is True.
|
||||
The default option elsewhere is False.
|
||||
width (int): The width in pixels of the iframe element containing the interface (used if inline=True)
|
||||
height (int): The height in pixels of the iframe element containing the interface (used if inline=True)
|
||||
encrypt (bool): If True, flagged data will be encrypted by key provided by creator at launch
|
||||
@ -438,8 +437,10 @@ class Blocks(BlockContext):
|
||||
getpass.getpass("Enter key for encryption: ")
|
||||
)
|
||||
|
||||
if hasattr(self, "enable_queue") and self.enable_queue is None:
|
||||
self.enable_queue = enable_queue
|
||||
if self.is_space and enable_queue is None:
|
||||
self.enable_queue = True
|
||||
else:
|
||||
self.enable_queue = enable_queue or False
|
||||
|
||||
config = self.get_config_file()
|
||||
self.config = config
|
||||
|
@ -3149,7 +3149,6 @@ class Button(Component):
|
||||
fn: Callable,
|
||||
inputs: List[Component],
|
||||
outputs: List[Component],
|
||||
queue=False,
|
||||
status_tracker: Optional[StatusTracker] = None,
|
||||
):
|
||||
"""
|
||||
@ -3165,7 +3164,6 @@ class Button(Component):
|
||||
fn,
|
||||
inputs,
|
||||
outputs,
|
||||
queue=queue,
|
||||
status_tracker=status_tracker,
|
||||
)
|
||||
|
||||
|
@ -107,7 +107,7 @@ class Interface(Blocks):
|
||||
outputs: str | Component | List[str | Component] = None,
|
||||
verbose: bool = False,
|
||||
examples: Optional[List[Any] | List[List[Any]] | str] = None,
|
||||
cache_examples: bool = False,
|
||||
cache_examples: Optional[bool] = None,
|
||||
examples_per_page: int = 10,
|
||||
live: bool = False,
|
||||
layout: str = "unaligned",
|
||||
@ -146,6 +146,10 @@ class Interface(Blocks):
|
||||
verbose (bool): DEPRECATED. Whether to print detailed information during launch.
|
||||
examples (Union[List[List[Any]], str]): sample inputs for the function; if provided, appears below the UI components and can be used to populate the interface. Should be nested list, in which the outer list consists of samples and each inner list consists of an input corresponding to each input component. A string path to a directory of examples can also be provided. If there are multiple input components and a directory is provided, a log.csv file must be present in the directory to link corresponding inputs.
|
||||
examples_per_page (int): If examples are provided, how many to display per page.
|
||||
cache_examples(Optional[bool]):
|
||||
If True, caches examples in the server for fast runtime in examples.
|
||||
The default option in HuggingFace Spaces is True.
|
||||
The default option elsewhere is False.
|
||||
live (bool): whether the interface should automatically reload on change.
|
||||
layout (str): Layout of input and output panels. "horizontal" arranges them as two columns of equal height, "unaligned" arranges them as two columns of unequal height, and "vertical" arranges them vertically.
|
||||
capture_session (bool): DEPRECATED. If True, captures the default graph and session (needed for Tensorflow 1.x)
|
||||
@ -291,7 +295,6 @@ class Interface(Blocks):
|
||||
|
||||
self.thumbnail = thumbnail
|
||||
theme = theme if theme is not None else os.getenv("GRADIO_THEME", "default")
|
||||
self.is_space = True if os.getenv("SYSTEM") == "spaces" else False
|
||||
DEPRECATED_THEME_MAP = {
|
||||
"darkdefault": "default",
|
||||
"darkhuggingface": "dark-huggingface",
|
||||
@ -440,8 +443,6 @@ class Interface(Blocks):
|
||||
[component.requires_permissions for component in self.input_components]
|
||||
)
|
||||
|
||||
self.enable_queue = enable_queue
|
||||
|
||||
self.favicon_path = None
|
||||
self.height = height
|
||||
self.width = width
|
||||
@ -495,8 +496,11 @@ class Interface(Blocks):
|
||||
else:
|
||||
component.label = "output " + str(i)
|
||||
|
||||
self.cache_examples = cache_examples
|
||||
if cache_examples:
|
||||
if self.is_space and cache_examples is None:
|
||||
self.cache_examples = True
|
||||
else:
|
||||
self.cache_examples = cache_examples or False
|
||||
if self.cache_examples:
|
||||
cache_interface_examples(self)
|
||||
|
||||
if self.allow_flagging != "never":
|
||||
@ -564,23 +568,26 @@ class Interface(Blocks):
|
||||
submit_fn,
|
||||
self.input_components,
|
||||
self.output_components,
|
||||
queue=self.enable_queue,
|
||||
status_tracker=status_tracker,
|
||||
)
|
||||
clear_btn.click(
|
||||
lambda: [
|
||||
component.default_value
|
||||
if hasattr(component, "default_value")
|
||||
else None
|
||||
for component in self.input_components + self.output_components
|
||||
]
|
||||
+ [True]
|
||||
+ ([False] if self.interpretation else []),
|
||||
(
|
||||
lambda: [
|
||||
component.default_value
|
||||
if hasattr(component, "default_value")
|
||||
else None
|
||||
for component in self.input_components + self.output_components
|
||||
]
|
||||
+ [True]
|
||||
+ ([False] if self.interpretation else [])
|
||||
),
|
||||
[],
|
||||
self.input_components
|
||||
+ self.output_components
|
||||
+ [input_component_column]
|
||||
+ ([interpret_component_column] if self.interpretation else []),
|
||||
(
|
||||
self.input_components
|
||||
+ self.output_components
|
||||
+ [input_component_column]
|
||||
+ ([interpret_component_column] if self.interpretation else [])
|
||||
),
|
||||
)
|
||||
if self.examples:
|
||||
examples = Dataset(
|
||||
|
@ -146,7 +146,6 @@ XRAY_CONFIG = {
|
||||
"trigger": "click",
|
||||
"inputs": [2, 6],
|
||||
"outputs": [7],
|
||||
"queue": False,
|
||||
"status_tracker": None,
|
||||
},
|
||||
{
|
||||
@ -154,7 +153,6 @@ XRAY_CONFIG = {
|
||||
"trigger": "click",
|
||||
"inputs": [2, 11],
|
||||
"outputs": [12],
|
||||
"queue": False,
|
||||
"status_tracker": None,
|
||||
},
|
||||
{
|
||||
@ -162,7 +160,6 @@ XRAY_CONFIG = {
|
||||
"trigger": "load",
|
||||
"inputs": [],
|
||||
"outputs": [14],
|
||||
"queue": False,
|
||||
"status_tracker": None,
|
||||
},
|
||||
],
|
||||
@ -316,7 +313,6 @@ XRAY_CONFIG_DIFF_IDS = {
|
||||
"trigger": "click",
|
||||
"inputs": [22, 6],
|
||||
"outputs": [7],
|
||||
"queue": False,
|
||||
"status_tracker": None,
|
||||
},
|
||||
{
|
||||
@ -324,7 +320,6 @@ XRAY_CONFIG_DIFF_IDS = {
|
||||
"trigger": "click",
|
||||
"inputs": [22, 11],
|
||||
"outputs": [12],
|
||||
"queue": False,
|
||||
"status_tracker": None,
|
||||
},
|
||||
],
|
||||
@ -477,7 +472,6 @@ XRAY_CONFIG_WITH_MISTAKE = {
|
||||
"trigger": "click",
|
||||
"inputs": [2, 6],
|
||||
"outputs": [7],
|
||||
"queue": False,
|
||||
"status_tracker": None,
|
||||
},
|
||||
{
|
||||
@ -485,7 +479,6 @@ XRAY_CONFIG_WITH_MISTAKE = {
|
||||
"trigger": "click",
|
||||
"inputs": [2, 11],
|
||||
"outputs": [12],
|
||||
"queue": False,
|
||||
"status_tracker": None,
|
||||
},
|
||||
],
|
||||
|
@ -332,7 +332,6 @@ def assert_configs_are_equivalent_besides_ids(config1, config2):
|
||||
assert mapping[i1] == i2, "{} does not match {}".format(d1, d2)
|
||||
for o1, o2 in zip(d1["outputs"], d2["outputs"]):
|
||||
assert mapping[o1] == o2, "{} does not match {}".format(d1, d2)
|
||||
assert d1["queue"] == d2["queue"], "{} does not match {}".format(d1, d2)
|
||||
|
||||
return True
|
||||
|
||||
|
@ -60,6 +60,7 @@ class TestStartServer(unittest.TestCase):
|
||||
networking.INITIAL_PORT_VALUE,
|
||||
networking.INITIAL_PORT_VALUE + networking.TRY_NUM_PORTS,
|
||||
)
|
||||
io.enable_queue = False
|
||||
_, local_path, _, server = networking.start_server(io, server_port=port)
|
||||
url = urllib.parse.urlparse(local_path)
|
||||
self.assertEquals(url.scheme, "http")
|
||||
|
Loading…
Reference in New Issue
Block a user