Repository: gradio-app/gradio

Issue:
Error with gradio 3.16.x by calling a function from a loaded space
### Describe the bug

Hello ! I think there is a bug when calling a function from a loaded space while using the 3.16.x version of gradio. 
No problem with the 3.15.0 version.

See below the logs from my "Whisper to Stable Diffusion" HF space, calling the spaces/sanchit-gandhi/whisper-large-v2 (whisper) : 



### Is there an existing issue for this?

- [X] I have searched the existing issues

### Reproduction

To reproduce the bug, You can duplicate this space : https://huggingface.co/spaces/fffiloni/whisper-to-stable-diffusion
and then change the gradio version from 3.15.0 to 3.16.x up to .2 

### Screenshot

_No response_

### Logs

```shell
Traceback (most recent call last):
  File "/home/user/.local/lib/python3.8/site-packages/gradio/routes.py", line 337, in run_predict
    output = await app.get_blocks().process_api(
  File "/home/user/.local/lib/python3.8/site-packages/gradio/blocks.py", line 1015, in process_api
    result = await self.call_function(
  File "/home/user/.local/lib/python3.8/site-packages/gradio/blocks.py", line 833, in call_function
    prediction = await anyio.to_thread.run_sync(
  File "/home/user/.local/lib/python3.8/site-packages/anyio/to_thread.py", line 31, in run_sync
    return await get_asynclib().run_sync_in_worker_thread(
  File "/home/user/.local/lib/python3.8/site-packages/anyio/_backends/_asyncio.py", line 937, in run_sync_in_worker_thread
    return await future
  File "/home/user/.local/lib/python3.8/site-packages/anyio/_backends/_asyncio.py", line 867, in run
    result = context.run(func, *args)
  File "app.py", line 85, in translate_better
    transcribe_text_result = whisper(audio, None, "transcribe", api_name="predict")
  File "/home/user/.local/lib/python3.8/site-packages/gradio/blocks.py", line 760, in __call__
    outputs = utils.synchronize_async(
  File "/home/user/.local/lib/python3.8/site-packages/gradio/utils.py", line 377, in synchronize_async
    return fsspec.asyn.sync(fsspec.asyn.get_loop(), func, *args, **kwargs)
  File "/home/user/.local/lib/python3.8/site-packages/fsspec/asyn.py", line 98, in sync
    raise return_result
  File "/home/user/.local/lib/python3.8/site-packages/fsspec/asyn.py", line 53, in _runner
    result[0] = await coro
  File "/home/user/.local/lib/python3.8/site-packages/gradio/blocks.py", line 1015, in process_api
    result = await self.call_function(
  File "/home/user/.local/lib/python3.8/site-packages/gradio/blocks.py", line 833, in call_function
    prediction = await anyio.to_thread.run_sync(
  File "/home/user/.local/lib/python3.8/site-packages/anyio/to_thread.py", line 31, in run_sync
    return await get_asynclib().run_sync_in_worker_thread(
  File "/home/user/.local/lib/python3.8/site-packages/anyio/_backends/_asyncio.py", line 937, in run_sync_in_worker_thread
    return await future
  File "/home/user/.local/lib/python3.8/site-packages/anyio/_backends/_asyncio.py", line 867, in run
    result = context.run(func, *args)
  File "/home/user/.local/lib/python3.8/site-packages/gradio/external.py", line 383, in fn
    data = json.dumps({"data": data, "fn_index": fn_index})
  File "/usr/local/lib/python3.8/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "/usr/local/lib/python3.8/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/local/lib/python3.8/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/usr/local/lib/python3.8/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type PosixPath is not JSON serializable
```



### System Info


Huggingface Hub
Gradio version : 1.16.x



### Severity

annoying


Discussion:
Thanks @fffiloni I think I know what the problem is!

Resolving patch:
diff --git a/gradio/serializing.py b/gradio/serializing.py
--- a/gradio/serializing.py
+++ b/gradio/serializing.py
@@ -119,7 +119,7 @@ def serialize(
         """
         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(


Test patch:
diff --git a/test/test_components.py b/test/test_components.py
--- a/test/test_components.py
+++ b/test/test_components.py
@@ -796,7 +796,6 @@ def test_component_functions(self):
         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 @@ def test_component_functions(self):
         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