Optimize client view_api method (#7178)

* Re-order code

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
This commit is contained in:
Freddy Boulton 2024-01-26 10:33:37 -08:00 committed by GitHub
parent ded5256c4a
commit 9f23b0bc54
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 11 additions and 6 deletions

View File

@ -0,0 +1,6 @@
---
"gradio": patch
"gradio_client": patch
---
fix:Optimize client view_api method

View File

@ -146,7 +146,7 @@ class Client:
self.upload_url = urllib.parse.urljoin(self.src, utils.UPLOAD_URL)
self.reset_url = urllib.parse.urljoin(self.src, utils.RESET_URL)
self.app_version = version.parse(self.config.get("version", "2.0"))
self._info = self._get_api_info()
self._info = None
self.session_hash = str(uuid.uuid4())
endpoint_class = (
@ -556,6 +556,8 @@ class Client:
}
"""
if not self._info:
self._info = self._get_api_info()
num_named_endpoints = len(self._info["named_endpoints"])
num_unnamed_endpoints = len(self._info["unnamed_endpoints"])
if num_named_endpoints == 0 and all_endpoints is None:

View File

@ -2304,12 +2304,9 @@ Received outputs:
if self.blocks[component["id"]].skip_api:
continue
label = component["props"].get("label", f"parameter_{i}")
# The config has the most specific API info (taking into account the parameters
# of the component), so we use that if it exists. Otherwise, we fallback to the
# Serializer's API info.
comp = self.get_component(component["id"])
assert isinstance(comp, components.Component)
info = comp.api_info()
info = component["api_info"]
example = comp.example_inputs()
python_type = client_utils.json_schema_to_python_type(info)
dependency_info["parameters"].append(
@ -2339,7 +2336,7 @@ Received outputs:
label = component["props"].get("label", f"value_{o}")
comp = self.get_component(component["id"])
assert isinstance(comp, components.Component)
info = comp.api_info()
info = component["api_info"]
example = comp.example_inputs()
python_type = client_utils.json_schema_to_python_type(info)
dependency_info["returns"].append(