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: 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/client.py b/client/python/gradio_client/client.py index a88ab32e357ac..31f55ee888986 100644 --- a/client/python/gradio_client/client.py +++ b/client/python/gradio_client/client.py @@ -403,9 +403,9 @@ 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.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/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/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 diff --git a/client/python/test/test_client.py b/client/python/test/test_client.py index b2cf922c08fca..a53854a36db61 100644 --- a/client/python/test/test_client.py +++ b/client/python/test/test_client.py @@ -740,18 +740,27 @@ 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", } + # 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", "description": "filepath or URL to file", } + 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/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() 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): 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