Fix missing docstrings (new PR) (#3740)

* Move documentation for _js into docstring, not a stray comment

* Add missing argument docstrings (and remove non-existent ones)

* Add changelog entry

* updated docstrings

* changelog

* contributors

* changelog

* formatting

* removed _js

---------

Co-authored-by: Aarni Koskela <akx@iki.fi>
This commit is contained in:
Abubakar Abid 2023-04-03 18:44:10 -05:00 committed by GitHub
parent ef3862e075
commit f50d6043db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 29 additions and 72 deletions

View File

@ -11,7 +11,7 @@ No changes to highlight.
## Documentation Changes:
No changes to highlight.
- Fix invalid argument docstrings, by [@akx](https://github.com/akx) in [PR 3740](https://github.com/gradio-app/gradio/pull/3740)
## Testing and Infrastructure Changes:
@ -23,7 +23,7 @@ No changes to highlight.
## Full Changelog:
- Fixed IPv6 listening to work with bracket [::1] notation. by [@dsully](https://github.com/dsully) in [PR 3695](https://github.com/gradio-app/gradio/pull/3695)
- Fixed IPv6 listening to work with bracket [::1] notation, by [@dsully](https://github.com/dsully) in [PR 3695](https://github.com/gradio-app/gradio/pull/3695)
## Contributors Shoutout:

View File

@ -182,8 +182,9 @@ class Block:
scroll_to_output: whether to scroll to output of dependency on trigger
show_progress: whether to show progress animation while running.
api_name: Defining this parameter exposes the endpoint in the api docs
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
js: Experimental parameter (API may change): 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.
batch: whether this function takes in a batch of inputs
max_batch_size: the maximum batch size to send to the function
cancels: a list of other events to cancel when this event is triggered. For example, setting cancels=[click_event] will cancel the click_event, where click_event is the return value of another components .click method.
@ -1063,8 +1064,8 @@ class Blocks(BlockContext):
Parameters:
fn_index: Index of function to run.
inputs: input data received from the frontend
username: name of user if authentication is set up (not used)
state: data stored from stateful components for session (key is input block id)
request: the gr.Request object containing information about the network request (e.g. IP address, headers, query parameters, username)
iterators: the in-progress iterators for each generator function (key is function index)
event_id: id of event that triggered this API call
event_data: data associated with the event trigger itself
@ -1261,7 +1262,6 @@ class Blocks(BlockContext):
demo.load(get_time, inputs=None, outputs=dt)
demo.launch()
"""
# _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.
if isinstance(self_or_cls, type):
warnings.warn("gr.Blocks.load() will be deprecated. Use gr.load() instead.")
if name is None:

View File

@ -1905,36 +1905,9 @@ class Image(
)
return self
def stream(
self,
fn: Callable,
inputs: List[Component],
outputs: List[Component],
_js: str | None = None,
api_name: str | None = None,
preprocess: bool = True,
postprocess: bool = True,
):
"""
This event is triggered when the user streams the component (e.g. a live webcam
component)
Parameters:
fn: Callable function
inputs: List of inputs
outputs: List of outputs
"""
# 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.
def check_streamable(self):
if self.source != "webcam":
raise ValueError("Image streaming only available if source is 'webcam'.")
super().stream(
fn,
inputs,
outputs,
_js=_js,
api_name=api_name,
preprocess=preprocess,
postprocess=postprocess,
)
def as_example(self, input_data: str | None) -> str:
if input_data is None:
@ -2419,38 +2392,11 @@ class Audio(
file_path = self.make_temp_copy_if_needed(y)
return {"name": file_path, "data": None, "is_file": True}
def stream(
self,
fn: Callable,
inputs: List[Component],
outputs: List[Component],
_js: str | None = None,
api_name: str | None = None,
preprocess: bool = True,
postprocess: bool = True,
):
"""
This event is triggered when the user streams the component (e.g. a live webcam
component)
Parameters:
fn: Callable function
inputs: List of inputs
outputs: List of outputs
"""
# _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.
def check_streamable(self):
if self.source != "microphone":
raise ValueError(
"Audio streaming only available if source is 'microphone'."
)
super().stream(
fn,
inputs,
outputs,
_js=_js,
api_name=api_name,
preprocess=preprocess,
postprocess=postprocess,
)
def style(
self,

View File

@ -113,7 +113,7 @@ class EventListenerMethod:
api_name: Defining this parameter exposes the endpoint in the api docs
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 exists
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.
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)
preprocess: If False, will not run preprocessing of component data before running 'fn' (e.g. leaving it as a base64 string if this method is called with the `Image` component).
@ -121,11 +121,13 @@ class EventListenerMethod:
cancels: A list of other events to cancel when this event is triggered. For example, setting cancels=[click_event] will cancel the click_event, where click_event is the return value of another components .click method. Functions that have not yet run (or generators that are iterating) will be cancelled, but functions that are currently running will be allowed to finish.
every: Run this event 'every' number of seconds while the client connection is open. Interpreted in seconds. Queue must be enabled.
"""
# _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.
if status_tracker:
warnings.warn(
"The 'status_tracker' parameter has been deprecated and has no effect."
)
if isinstance(self, Streamable):
self.check_streamable()
dep, dep_index = self.trigger.set_event_trigger(
self.event_name,
fn,
@ -239,6 +241,9 @@ class Streamable(EventListener):
component). This method can be used when this component is in a Gradio Blocks.
"""
def check_streamable(self):
pass
@document("*blur", inherit=True)
class Blurrable(EventListener):

View File

@ -602,9 +602,10 @@ def special_args(
Checks if function has special arguments Request or EventData (via annotation) or Progress (via default value).
If inputs is provided, these values will be loaded into the inputs array.
Parameters:
block_fn: function to check.
fn: function to check.
inputs: array to load special arguments into.
request: request to load into inputs.
event_data: event-related data to load into inputs.
Returns:
updated inputs, progress index, event data index.
"""

View File

@ -209,9 +209,9 @@ class Queue:
async def gather_event_data(self, event: Event, receive_timeout=60) -> bool:
"""
Gather data for the event
Parameters:
event:
event: the Event to gather data for
receive_timeout: how long to wait for data to be received from frontend
"""
if not event.data:
client_awake = await self.send_message(event, {"msg": "send_data"})

View File

@ -208,8 +208,8 @@ def integration_analytics(data: Dict[str, Any]) -> None:
def error_analytics(message: str) -> None:
"""
Send error analytics if there is network
:param ip_address: IP address where error occurred
:param message: Details about error
Parameters:
message: Details about error
"""
data = {"ip_address": get_local_ip_address(), "error": message}

View File

@ -26,14 +26,19 @@ DEMOS_TO_SKIP = {"all_demos", "reset_components", "custom_path", "kitchen_sink_r
def upload_demo_to_space(
demo_name: str, space_id: str, hf_token: str, gradio_version: Optional[str], gradio_wheel_url: Optional[str] = None
demo_name: str,
space_id: str,
hf_token: str,
gradio_version: str | None,
gradio_wheel_url: str | None = None
):
"""Upload a demo in the demo directory to a huggingface space.
Args:
Parameters:
demo_name: The name of the demo to upload.
space_id: The id of the space to upload the demo to.
hf_token: HF api token. Need to have permission to write to space_id for this to work.
gradio_version: If not None, will set the gradio version in the created space to the given version.
gradio_version: If not None, will set the gradio version in the created Space to the given version.
gradio_wheel_url: If not None, will install the version of gradio using the wheel url in the created Space.
"""
with tempfile.TemporaryDirectory() as tmpdir:
@ -91,4 +96,4 @@ if __name__ == "__main__":
for demo in demos:
if hello_world_version != latest_gradio_stable:
upload_demo_to_space(demo_name=demo, space_id="gradio/" + demo, hf_token=AUTH_TOKEN, gradio_version=latest_gradio_stable)
upload_demo_to_space(demo_name=demo, space_id="gradio/" + demo + "_main", hf_token=AUTH_TOKEN, gradio_version=gradio_version, gradio_wheel_url=gradio_wheel_url)
upload_demo_to_space(demo_name=demo, space_id="gradio/" + demo + "_main", hf_token=AUTH_TOKEN, gradio_version=gradio_version, gradio_wheel_url=gradio_wheel_url)