Repository: gradio-app/gradio

Issue:
Cannot load examples with missing file paths
### Describe the bug

For the moment it is only possible to either provide no file path in all example rows, either existing file paths for all examples.

This is due to exception raising at line _example[i] = component.as_example(ex)_, in _components.py_, where the File component expects str, bytes or os.PathLike object, not NoneType.

I'd like to have the possibility to add file paths only for some on the examples, as it is easily doable with other components eg Text.

(I'm using Gradio 3.7)

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Reproduction

def simple_fct(text, file):
    return text + 'ok'


demo = gr.Interface(
    simple_fct,
    ['text', 'file'],
    ['text'],
    examples=[['text1', 'main_feng.py'], ['', None]]
)

demo.launch(debug=True) 


### Screenshot

_No response_

### Logs

```shell
Traceback (most recent call last):
  File <path>Python310\lib\site-packages\gradio\interface.py", line 651, in __init__
    self.examples_handler = Examples(
  File <path>Python310\lib\site-packages\gradio\examples.py", line 44, in create_examples
    examples_obj = Examples(
  File <path>Python310\lib\site-packages\gradio\examples.py", line 215, in __init__
    self.dataset = Dataset(
  File <path>Python310\lib\site-packages\gradio\components.py", line 3809, in __init__
    example[i] = component.as_example(ex)
  File <path>Python310\lib\site-packages\gradio\components.py", line 2209, in as_example
    return Path(input_data).name
  File <path>Python310\lib\pathlib.py", line 960, in __new__
    self = cls._from_parts(args)
  File <path>Python310\lib\pathlib.py", line 594, in _from_parts
    drv, root, parts = self._parse_args(args)
  File <path>Python310\lib\pathlib.py", line 578, in _parse_args
    a = os.fspath(a)
TypeError: expected str, bytes or os.PathLike object, not NoneType

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "main.py", line 24, in <module>
    demo = gr.Interface(
  File <path>Python310\lib\site-packages\gradio\interface.py", line 432, in __init__
    with self:
  File <path>Python310\lib\site-packages\gradio\blocks.py", line 971, in __exit__
    self.config = self.get_config_file()
  File <path>Python310\lib\site-packages\gradio\blocks.py", line 947, in get_config_file
    "props": utils.delete_none(block.get_config())
  File <path>Python310\lib\site-packages\gradio\components.py", line 3822, in get_config
    "headers": self.headers,
AttributeError: 'Dataset' object has no attribute 'headers'

Process finished with exit code 1
```


### System Info

```shell
gradio 3.7 run from PyCharm 2022.2.3 (Community Edition)
```


### Severity

annoying


Discussion:
Thanks for filing @SoranaBaciu !

Resolving patch:
diff --git a/gradio/components.py b/gradio/components.py
--- a/gradio/components.py
+++ b/gradio/components.py
@@ -2023,7 +2023,7 @@ def style(
         )
 
     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 @@ def style(
             **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 @@ def style(self, **kwargs):
         )
 
     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")


Test patch:
diff --git a/test/test_components.py b/test/test_components.py
--- a/test/test_components.py
+++ b/test/test_components.py
@@ -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")