From ac5fb4f30484a9cd82460f81025d1108befb204c Mon Sep 17 00:00:00 2001 From: freddyaboulton Date: Wed, 10 May 2023 15:04:18 -0400 Subject: [PATCH 1/7] Fix output file type info --- client/python/gradio_client/client.py | 2 +- client/python/gradio_client/utils.py | 2 +- client/python/test/test_client.py | 2 ++ gradio/blocks.py | 9 +++++++-- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/client/python/gradio_client/client.py b/client/python/gradio_client/client.py index a88ab32e357ac..4f5af1cca3184 100644 --- a/client/python/gradio_client/client.py +++ b/client/python/gradio_client/client.py @@ -405,7 +405,7 @@ def view_api( # Versions of Gradio older than 3.28.3 returned format of the API info # from the /info endpoint - if version.parse(self.config.get("version", "2.0")) > version.Version("3.28.3"): + if version.parse(self.config.get("version", "2.0")) > version.Version("3.29.0"): r = requests.get(api_info_url, headers=self.headers) if r.ok: info = r.json() diff --git a/client/python/gradio_client/utils.py b/client/python/gradio_client/utils.py index a9bcec285aa6e..75b2c5666e917 100644 --- a/client/python/gradio_client/utils.py +++ b/client/python/gradio_client/utils.py @@ -29,7 +29,7 @@ CONFIG_URL = "/config" API_INFO_URL = "/info" RAW_API_INFO_URL = "/info?serialize=False" -SPACE_FETCHER_URL = "https://gradio-space-api-fetcher-v2.hf.space/api" +SPACE_FETCHER_URL = "https://freddyaboulton-space-api-fetcher-dev.hf.space/api" RESET_URL = "/reset" SPACE_URL = "https://hf.space/{}" diff --git a/client/python/test/test_client.py b/client/python/test/test_client.py index b2cf922c08fca..465c4b9323a75 100644 --- a/client/python/test/test_client.py +++ b/client/python/test/test_client.py @@ -740,6 +740,7 @@ def test_file_io(self, file_io_demo): info = client.view_api(return_format="dict") inputs = info["named_endpoints"]["/predict"]["parameters"] outputs = info["named_endpoints"]["/predict"]["returns"] + assert inputs[0]["type"]["type"] == "array" assert inputs[0]["python_type"] == { "type": "List[str]", "description": "List of filepath(s) or URL(s) to files", @@ -748,6 +749,7 @@ def test_file_io(self, file_io_demo): "type": "str", "description": "filepath or URL to file", } + assert inputs[0]["type"]["type"] == "array" assert outputs[0]["python_type"] == { "type": "List[str]", "description": "List of filepath(s) or URL(s) to files", diff --git a/gradio/blocks.py b/gradio/blocks.py index f890206882afe..60a65fa8fc395 100644 --- a/gradio/blocks.py +++ b/gradio/blocks.py @@ -550,8 +550,13 @@ def get_api_info(config: dict, serialize: bool = True): continue label = component["props"].get("label", f"value_{o}") serializer = serializing.COMPONENT_MAPPING[type]() - assert isinstance(serializer, serializing.Serializable) - info = serializer.api_info() + if component.get("api_info") and after_new_format: + info = component["api_info"] + example = component["example_inputs"]["serialized"] + else: + assert isinstance(serializer, serializing.Serializable) + info = serializer.api_info() + example = serializer.example_inputs()["raw"] python_info = info["info"] if serialize and info["serialized_info"]: python_info = serializer.serialized_info() From 7457d2c0b25d950e3fd34e14078e8acfaabf4f5f Mon Sep 17 00:00:00 2001 From: freddyaboulton Date: Wed, 10 May 2023 15:54:51 -0400 Subject: [PATCH 2/7] Fix example inputs --- client/python/gradio_client/serializing.py | 11 +++++++++++ client/python/test/test_client.py | 8 +++++++- gradio/components.py | 6 ++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/client/python/gradio_client/serializing.py b/client/python/gradio_client/serializing.py index dfec41c1376e8..c0529e6c9976a 100644 --- a/client/python/gradio_client/serializing.py +++ b/client/python/gradio_client/serializing.py @@ -231,11 +231,22 @@ def api_info(self) -> dict[str, dict | bool]: return self._single_file_api_info() def example_inputs(self) -> dict[str, Any]: + return self._single_file_example_inputs() + + def _single_file_example_inputs(self) -> dict[str, Any]: return { "raw": {"is_file": False, "data": media_data.BASE64_FILE}, "serialized": "https://github.com/gradio-app/gradio/raw/main/test/test_files/sample_file.pdf", } + def _multiple_file_example_inputs(self) -> dict[str, Any]: + return { + "raw": [{"is_file": False, "data": media_data.BASE64_FILE}], + "serialized": [ + "https://github.com/gradio-app/gradio/raw/main/test/test_files/sample_file.pdf" + ], + } + def _serialize_single( self, x: str | FileData | None, load_dir: str | Path = "" ) -> FileData | None: diff --git a/client/python/test/test_client.py b/client/python/test/test_client.py index 465c4b9323a75..7647910179451 100644 --- a/client/python/test/test_client.py +++ b/client/python/test/test_client.py @@ -740,20 +740,26 @@ def test_file_io(self, file_io_demo): info = client.view_api(return_format="dict") inputs = info["named_endpoints"]["/predict"]["parameters"] outputs = info["named_endpoints"]["/predict"]["returns"] + assert inputs[0]["type"]["type"] == "array" assert inputs[0]["python_type"] == { "type": "List[str]", "description": "List of filepath(s) or URL(s) to files", } + assert isinstance(inputs[0]["example_input"], list) + assert inputs[1]["python_type"] == { "type": "str", "description": "filepath or URL to file", } - assert inputs[0]["type"]["type"] == "array" + assert isinstance(inputs[1]["example_input"], str) + assert outputs[0]["python_type"] == { "type": "List[str]", "description": "List of filepath(s) or URL(s) to files", } + assert outputs[0]["type"]["type"] == "array" + assert outputs[1]["python_type"] == { "type": "str", "description": "filepath or URL to file", diff --git a/gradio/components.py b/gradio/components.py index bc45926cd2172..9c9e73ec96f4f 100644 --- a/gradio/components.py +++ b/gradio/components.py @@ -2797,6 +2797,12 @@ def serialized_info(self): else: return self._multiple_file_serialized_info() + def example_inputs(self) -> dict[str, Any]: + if self.file_count == "single": + return self._single_file_example_inputs() + else: + return self._multiple_file_example_inputs() + @document("style") class Dataframe(Changeable, Selectable, IOComponent, JSONSerializable): From 434da7f955c3d0ba4243828106f8b43cad5d7bab Mon Sep 17 00:00:00 2001 From: freddyaboulton Date: Wed, 10 May 2023 16:01:11 -0400 Subject: [PATCH 3/7] CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cd0c850b73bcd..8f09d698747c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ - Records username when flagging by [@abidlabs](https://github.com/abidlabs) in [PR 4135](https://github.com/gradio-app/gradio/pull/4135) - Fix website build issue by [@aliabd](https://github.com/aliabd) in [PR 4142](https://github.com/gradio-app/gradio/pull/4142) +- Fix lang agnostic type info for `gr.File(file_count='multiple')` output components by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 4153](https://github.com/gradio-app/gradio/pull/4153) + ## Documentation Changes: From 63a0918b54b9a7160f4dfbbba1e2098fd0e5a453 Mon Sep 17 00:00:00 2001 From: freddyaboulton Date: Wed, 10 May 2023 16:02:20 -0400 Subject: [PATCH 4/7] Update client --- client/python/gradio_client/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/python/gradio_client/client.py b/client/python/gradio_client/client.py index 4f5af1cca3184..31f55ee888986 100644 --- a/client/python/gradio_client/client.py +++ b/client/python/gradio_client/client.py @@ -403,7 +403,7 @@ def view_api( else: api_info_url = urllib.parse.urljoin(self.src, utils.RAW_API_INFO_URL) - # Versions of Gradio older than 3.28.3 returned format of the API info + # Versions of Gradio older than 3.29.0 returned format of the API info # from the /info endpoint if version.parse(self.config.get("version", "2.0")) > version.Version("3.29.0"): r = requests.get(api_info_url, headers=self.headers) From 461160b1c6714d64967c202444ee20d750b17ae3 Mon Sep 17 00:00:00 2001 From: freddyaboulton Date: Wed, 10 May 2023 16:19:30 -0400 Subject: [PATCH 5/7] Add test --- client/python/test/test_client.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/python/test/test_client.py b/client/python/test/test_client.py index 7647910179451..a53854a36db61 100644 --- a/client/python/test/test_client.py +++ b/client/python/test/test_client.py @@ -746,7 +746,8 @@ def test_file_io(self, file_io_demo): "type": "List[str]", "description": "List of filepath(s) or URL(s) to files", } - assert isinstance(inputs[0]["example_input"], list) + # Will change to list when we do the next gradio release + assert isinstance(inputs[0]["example_input"], str) assert inputs[1]["python_type"] == { "type": "str", From 163c93457b352cff8b8884dfb4dc143ab9d55352 Mon Sep 17 00:00:00 2001 From: freddyaboulton Date: Wed, 10 May 2023 18:28:23 -0400 Subject: [PATCH 6/7] Bump version --- client/python/CHANGELOG.md | 29 +++++++++++++++++++++++++ client/python/gradio_client/utils.py | 2 +- client/python/gradio_client/version.txt | 2 +- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/client/python/CHANGELOG.md b/client/python/CHANGELOG.md index ff5d55b35ddb7..8b6ef0b61f423 100644 --- a/client/python/CHANGELOG.md +++ b/client/python/CHANGELOG.md @@ -4,6 +4,35 @@ No changes to highlight. +## Bug Fixes: +- Fix example inputs for `gr.File(file_count='multiple')` output components by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 4153](https://github.com/gradio-app/gradio/pull/4153) + +## Documentation Changes: + +No changes to highlight. + +## Testing and Infrastructure Changes: + +No changes to highlight. + +## Breaking Changes: + +No changes to highlight. + +## Full Changelog: + +No changes to highlight. + +## Contributors Shoutout: + +No changes to highlight. + +# 0.2.2 + +## New Features: + +No changes to highlight. + ## Bug Fixes: - Only send request to `/info` route if demo version is above `3.28.3` by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 4109](https://github.com/gradio-app/gradio/pull/4109) diff --git a/client/python/gradio_client/utils.py b/client/python/gradio_client/utils.py index 75b2c5666e917..a9bcec285aa6e 100644 --- a/client/python/gradio_client/utils.py +++ b/client/python/gradio_client/utils.py @@ -29,7 +29,7 @@ CONFIG_URL = "/config" API_INFO_URL = "/info" RAW_API_INFO_URL = "/info?serialize=False" -SPACE_FETCHER_URL = "https://freddyaboulton-space-api-fetcher-dev.hf.space/api" +SPACE_FETCHER_URL = "https://gradio-space-api-fetcher-v2.hf.space/api" RESET_URL = "/reset" SPACE_URL = "https://hf.space/{}" diff --git a/client/python/gradio_client/version.txt b/client/python/gradio_client/version.txt index ee1372d33a29e..7179039691ce0 100644 --- a/client/python/gradio_client/version.txt +++ b/client/python/gradio_client/version.txt @@ -1 +1 @@ -0.2.2 +0.2.3 From ec3c3d686f307304bb1b50abb0fac75f3ecb21fe Mon Sep 17 00:00:00 2001 From: freddyaboulton Date: Wed, 10 May 2023 19:35:38 -0400 Subject: [PATCH 7/7] Bump min client version --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index fe98e442b9404..d0ea9d0effc31 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,7 @@ aiohttp altair>=4.2.0 fastapi ffmpy -gradio_client>=0.2.1 +gradio_client>=0.2.3 httpx huggingface_hub>=0.13.0 Jinja2