Fix api info for File component (#4153)

* Fix output file type info

* Fix example inputs

* CHANGELOG

* Update client

* Add test

* Bump version

* Bump min client version
This commit is contained in:
Freddy Boulton 2023-05-10 19:52:07 -04:00 committed by GitHub
parent ccdaac1395
commit 3227a9b703
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 68 additions and 6 deletions

View File

@ -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:

View File

@ -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)

View File

@ -403,9 +403,9 @@ class Client:
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()

View File

@ -231,11 +231,22 @@ class FileSerializable(Serializable):
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:

View File

@ -1 +1 @@
0.2.2
0.2.3

View File

@ -740,18 +740,27 @@ class TestAPIInfo:
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",

View File

@ -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()

View File

@ -2797,6 +2797,12 @@ class File(
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):

View File

@ -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