From 03491ef49708753fc51566c3dc17df09ae98fb98 Mon Sep 17 00:00:00 2001 From: Abubakar Abid Date: Mon, 13 Nov 2023 12:52:35 -0800 Subject: [PATCH] Fix docstrings and default value for `api_name` (#6405) * api names * add changeset * lint --------- Co-authored-by: gradio-pr-bot --- .changeset/light-symbols-know.md | 5 +++++ gradio/blocks.py | 2 +- gradio/events.py | 2 +- gradio/helpers.py | 6 +++--- gradio/interface.py | 2 +- 5 files changed, 11 insertions(+), 6 deletions(-) create mode 100644 .changeset/light-symbols-know.md diff --git a/.changeset/light-symbols-know.md b/.changeset/light-symbols-know.md new file mode 100644 index 0000000000..a8eceeb9d4 --- /dev/null +++ b/.changeset/light-symbols-know.md @@ -0,0 +1,5 @@ +--- +"gradio": patch +--- + +fix:Fix docstrings and default value for `api_name` diff --git a/gradio/blocks.py b/gradio/blocks.py index 2651c4cb41..5dba7f1c83 100644 --- a/gradio/blocks.py +++ b/gradio/blocks.py @@ -836,7 +836,7 @@ class Blocks(BlockContext, BlocksEvents, metaclass=BlocksMeta): postprocess: whether to run the postprocess methods of components scroll_to_output: whether to scroll to output of dependency on trigger show_progress: whether to show progress animation while running. - api_name: defines how the endpoint appears in the API docs. Can be a string, None, or False. If False, the endpoint will not be exposed in the api docs. If set to None, the endpoint will be exposed in the api docs as an unnamed endpoint, although this behavior will be changed in Gradio 4.0. If set to a string, the endpoint will be exposed in the api docs with the given name. + api_name: defines how the endpoint appears in the API docs. Can be a string, None, or False. If set to a string, the endpoint will be exposed in the API docs with the given name. If None (default), the name of the function will be used as the API endpoint. If False, the endpoint will not be exposed in the API docs and downstream apps (including those that `gr.load` this app) will not be able to use this event. js: Optional frontend js method to run before running 'fn'. Input arguments for js method are values of 'inputs' and 'outputs', return should be a list of values for output components no_target: if True, sets "targets" to [], used for Blocks "load" event queue: If True, will place the request on the queue, if the queue has been enabled. If False, will not put this event on the queue, even if the queue has been enabled. If None, will use the queue setting of the gradio app. diff --git a/gradio/events.py b/gradio/events.py index 6a6c04866e..5b215b0916 100644 --- a/gradio/events.py +++ b/gradio/events.py @@ -215,7 +215,7 @@ class EventListener(str): fn: the function to call when this event is triggered. Often a machine learning model's prediction function. Each parameter of the function corresponds to one input component, and the function should return a single value or a tuple of values, with each element in the tuple corresponding to one output component. inputs: List of gradio.components to use as inputs. If the function takes no inputs, this should be an empty list. outputs: List of gradio.components to use as outputs. If the function returns no outputs, this should be an empty list. - api_name: Defines how the endpoint appears in the API docs. Can be a string, None, or False. If False, the endpoint will not be exposed in the api docs. If set to None, the endpoint will be given the name of the python function fn. If no fn is passed in, it will be given the name 'unnamed'. If set to a string, the endpoint will be exposed in the api docs with the given name. + api_name: defines how the endpoint appears in the API docs. Can be a string, None, or False. If set to a string, the endpoint will be exposed in the API docs with the given name. If None (default), the name of the function will be used as the API endpoint. If False, the endpoint will not be exposed in the API docs and downstream apps (including those that `gr.load` this app) will not be able to use this event. scroll_to_output: If True, will scroll to output component on completion show_progress: If True, will show progress animation while pending queue: If True, will place the request on the queue, if the queue has been enabled. If False, will not put this event on the queue, even if the queue has been enabled. If None, will use the queue setting of the gradio app. diff --git a/gradio/helpers.py b/gradio/helpers.py index d70c8dda18..4cbd89006e 100644 --- a/gradio/helpers.py +++ b/gradio/helpers.py @@ -52,7 +52,7 @@ def create_examples( run_on_click: bool = False, preprocess: bool = True, postprocess: bool = True, - api_name: str | None | Literal[False] = None, + api_name: str | Literal[False] = "load_example", batch: bool = False, ): """Top-level synchronous function that creates Examples. Provided for backwards compatibility, i.e. so that gr.Examples(...) can be used to create the Examples component.""" @@ -103,7 +103,7 @@ class Examples: run_on_click: bool = False, preprocess: bool = True, postprocess: bool = True, - api_name: str | None | Literal[False] = False, + api_name: str | Literal[False] = "load_example", batch: bool = False, _initiated_directly: bool = True, ): @@ -120,7 +120,7 @@ class Examples: run_on_click: if cache_examples is False, clicking on an example does not run the function when an example is clicked. Set this to True to run the function when an example is clicked. Has no effect if cache_examples is True. preprocess: if True, preprocesses the example input before running the prediction function and caching the output. Only applies if cache_examples is True. postprocess: if True, postprocesses the example output after running the prediction function and before caching. Only applies if cache_examples is True. - api_name: Defines how the event associated with clicking on the examples appears in the API docs. Can be a string, None, or False. If False (default), the endpoint will not be exposed in the api docs. If set to None, the endpoint will be exposed in the api docs as an unnamed endpoint, although this behavior will be changed in Gradio 4.0. If set to a string, the endpoint will be exposed in the api docs with the given name. + api_name: Defines how the event associated with clicking on the examples appears in the API docs. Can be a string or False. If set to a string, the endpoint will be exposed in the API docs with the given name. If False, the endpoint will not be exposed in the API docs and downstream apps (including those that `gr.load` this app) will not be able to use the example function. batch: If True, then the function should process a batch of inputs, meaning that it should accept a list of input values for each parameter. Used only if cache_examples is True. """ if _initiated_directly: diff --git a/gradio/interface.py b/gradio/interface.py index 1901c02edd..7539b0eff8 100644 --- a/gradio/interface.py +++ b/gradio/interface.py @@ -139,7 +139,7 @@ class Interface(Blocks): analytics_enabled: Whether to allow basic telemetry. If None, will use GRADIO_ANALYTICS_ENABLED environment variable if defined, or default to True. batch: If True, then the function should process a batch of inputs, meaning that it should accept a list of input values for each parameter. The lists should be of equal length (and be up to length `max_batch_size`). The function is then *required* to return a tuple of lists (even if there is only 1 output component), with each list in the tuple corresponding to one output component. max_batch_size: Maximum number of inputs to batch together if this is called from the queue (only relevant if batch=True) - api_name: Defines how the endpoint appears in the API docs. Can be a string, None, or False. If False or None, the endpoint will not be exposed in the api docs. If set to a string, the endpoint will be exposed in the api docs with the given name. Default value is "predict". + api_name: defines how the endpoint appears in the API docs. Can be a string, None, or False. If set to a string, the endpoint will be exposed in the API docs with the given name. If None, the name of the prediction function will be used as the API endpoint. If False, the endpoint will not be exposed in the API docs and downstream apps (including those that `gr.load` this app) will not be able to use this event. allow_duplication: If True, then will show a 'Duplicate Spaces' button on Hugging Face Spaces. concurrency_limit: If set, this this is the maximum number of events that can be running simultaneously. Extra requests will be queued. """