Skip to content

Commit

Permalink
Fix example inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
freddyaboulton committed May 10, 2023
1 parent c3f7773 commit b78e5f1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
11 changes: 11 additions & 0 deletions client/python/gradio_client/serializing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 7 additions & 1 deletion client/python/test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions gradio/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit b78e5f1

Please sign in to comment.