mirror of
https://github.com/gradio-app/gradio.git
synced 2025-04-06 12:30:29 +08:00
Allow None in as_example for files (#2588)
* Fix file examples * Changelog * Fix changelog version name previous release
This commit is contained in:
parent
e6cda90b69
commit
f0d1cdf08f
@ -4,7 +4,7 @@
|
||||
No changes to highlight.
|
||||
|
||||
## Bug Fixes:
|
||||
No changes to highlight.
|
||||
* Fixed bug where None could not be used for File,Model3D, and Audio examples by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 2588](https://github.com/gradio-app/gradio/pull/2588)
|
||||
|
||||
## Documentation Changes:
|
||||
No changes to highlight.
|
||||
@ -22,7 +22,7 @@ No changes to highlight.
|
||||
No changes to highlight.
|
||||
|
||||
|
||||
# Version 3.8.1de# Version 1
|
||||
# Version 3.8.2
|
||||
|
||||
## Bug Fixes:
|
||||
|
||||
|
@ -2023,7 +2023,7 @@ class Audio(
|
||||
)
|
||||
|
||||
def as_example(self, input_data: str) -> str:
|
||||
return Path(input_data).name
|
||||
return Path(input_data).name if input_data else ""
|
||||
|
||||
|
||||
@document("change", "clear", "style")
|
||||
@ -2202,8 +2202,10 @@ class File(Changeable, Clearable, Uploadable, IOComponent, FileSerializable):
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
def as_example(self, input_data: str | List) -> str:
|
||||
if isinstance(input_data, list):
|
||||
def as_example(self, input_data: str | List | None) -> str | List[str]:
|
||||
if input_data is None:
|
||||
return ""
|
||||
elif isinstance(input_data, list):
|
||||
return [Path(file).name for file in input_data]
|
||||
else:
|
||||
return Path(input_data).name
|
||||
@ -3615,7 +3617,7 @@ class Model3D(Changeable, Editable, Clearable, IOComponent, FileSerializable):
|
||||
)
|
||||
|
||||
def as_example(self, input_data: str) -> str:
|
||||
return Path(input_data).name
|
||||
return Path(input_data).name if input_data else ""
|
||||
|
||||
|
||||
@document("change", "clear")
|
||||
|
@ -1921,10 +1921,11 @@ def test_dataframe_as_example_converts_dataframes():
|
||||
assert df_comp.as_example(np.array([[1, 2], [3, 4.0]])) == [[1.0, 2.0], [3.0, 4.0]]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("component", [gr.Model3D, gr.File])
|
||||
@pytest.mark.parametrize("component", [gr.Model3D, gr.File, gr.Audio])
|
||||
def test_as_example_returns_file_basename(component):
|
||||
component = component()
|
||||
assert component.as_example("/home/freddy/sources/example.ext") == "example.ext"
|
||||
assert component.as_example(None) == ""
|
||||
|
||||
|
||||
@patch("gradio.components.IOComponent.as_example")
|
||||
|
Loading…
x
Reference in New Issue
Block a user