Fix file serialization so that output is json serializable (#2999)

* Add comments

* CHANGELOG

Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
This commit is contained in:
Freddy Boulton 2023-01-17 20:29:27 +01:00 committed by GitHub
parent 43f0bedf52
commit 2bbec4b41e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 3 deletions

View File

@ -6,7 +6,8 @@ No changes to highlight.
## Bug Fixes:
* Fixes bug where interpretation event was not configured correctly by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 2993](https://github.com/gradio-app/gradio/pull/2993)
* Fix relative import bug in reload mode by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 2992](https://github.com/gradio-app/gradio/pull/2992)
* Fixes bug where png files were not being recognized when uploadin images by [@abidlabs](https://github.com/abidlabs) in [PR 3002](https://github.com/gradio-app/gradio/pull/3002)
* Fix bug where file serialization output was not JSON serializable by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 2999](https://github.com/gradio-app/gradio/pull/2999)
* Fixes bug where png files were not being recognized when uploading images by [@abidlabs](https://github.com/abidlabs) in [PR 3002](https://github.com/gradio-app/gradio/pull/3002)
## Documentation Changes:
No changes to highlight.

View File

@ -119,7 +119,7 @@ class FileSerializable(Serializable):
"""
if x is None or x == "":
return None
filename = Path(load_dir) / x
filename = str(Path(load_dir) / x)
return {
"name": filename,
"data": processing_utils.encode_url_or_file_to_base64(

View File

@ -796,7 +796,6 @@ class TestAudio:
assert isinstance(audio_input.preprocess(x_wav), str)
with pytest.raises(ValueError):
gr.Audio(type="unknown")
audio_input = gr.Audio(type="numpy")
# Output functionalities
y_audio = gr.processing_utils.decode_base64_to_file(
@ -829,6 +828,15 @@ class TestAudio:
output2 = audio_output.postprocess(y_audio.name)
assert output1 == output2
def test_serialize(self):
audio_input = gr.Audio()
assert audio_input.serialize("test/test_files/audio_sample.wav") == {
"data": media_data.BASE64_AUDIO["data"],
"is_file": False,
"orig_name": "audio_sample.wav",
"name": "test/test_files/audio_sample.wav",
}
def test_tokenize(self):
"""
Tokenize, get_masked_inputs