How do we provide AUDIO Examples when using Blocks?
Update: Editing question now that I seem to be on the correct track, but having trouble with Audio specifically.  If you could scroll down my 3rd message in this thread, I’d appreciate it. Thanks.When we’re not usinggr.Interface(...), but rather usinggr.Blocks(), how/where do we… specify examples?I’m not finding any information in theKey Features GuideorMore on Examplesfor the case of Blocks, or the docs page forBlocks.I’m also not seeingexamples=on the list of supported kwargs togr.Blocks().  And there doesn’t seem to be anygr.Example()object; the docs go from “Dropdown” to “File”, skipping the letter E.
2023-05-01T21:55:27Z
Wow, ok, just found the actualgr.Examplesobject! lol. Didn’t see it further down the screen.You know, it might be a good idea to mention its existence somewhere in the “More on Examples” page.
2023-05-01T22:31:58Z
UPDATE:Ok, I’m having a hard time specifying Audio examples. Maybe I just need to search around for examples.  I’m only finding Images and text.I load in a couple audio waveforms, convert them to channels-last PCM int 16 values, and supply as in the examples string, a tuple of( sample_rate, waveform_numpy_int16 ).But I’m getting this error:gr.Examples(
  File "/fsx/shawley/envs_sm/aa/lib/python3.10/site-packages/gradio/helpers.py", line 55, in create_examples
    examples_obj = Examples(
  File "/fsx/shawley/envs_sm/aa/lib/python3.10/site-packages/gradio/helpers.py", line 228, in __init__
    self.dataset = components.Dataset(
  File "/fsx/shawley/envs_sm/aa/lib/python3.10/site-packages/gradio/components.py", line 6136, in __init__
    example[i] = component.as_example(ex)
  File "/fsx/shawley/envs_sm/aa/lib/python3.10/site-packages/gradio/components.py", line 2563, in as_example
    return Path(input_data).name if input_data else ""
  File "/home/ec2-user/anaconda3/lib/python3.10/pathlib.py", line 960, in __new__
    self = cls._from_parts(args)
  File "/home/ec2-user/anaconda3/lib/python3.10/pathlib.py", line 594, in _from_parts
    drv, root, parts = self._parse_args(args)
  File "/home/ec2-user/anaconda3/lib/python3.10/pathlib.py", line 578, in _parse_args
    a = os.fspath(a)
TypeError: expected str, bytes or os.PathLike object, not tupleBut Audio objects pass tuples to their routines right?  I tried just passing in the waveform, but my processing routine had expected tuples so it didn’t work.If I try using filename strings as examples, then when they get to my processing function the variable there isNoneinstead of the string I provided.
2023-05-01T23:44:04Z
Ok, one workaround is to turn off caching, outputs, fn, and execute on click.  Then the inputs get populated and users can just go press Submit.   Works for now.
2023-05-02T14:11:54Z
Hi@drscotthawley!You should be able to pass in a filepath to a.wavor.mp3file. Here is an example:github.comgradio-app/gradio/blob/main/demo/unispeech-speaker-verification/run.py#L97"Try it with your own voice!")article = ("<p style='text-align: center'>""<a href='https://huggingface.co/microsoft/unispeech-sat-large-sv' target='_blank'>🎙️ Learn more about UniSpeech-SAT</a> | ""<a href='https://arxiv.org/abs/2110.05752' target='_blank'>📚 UniSpeech-SAT paper</a> | ""<a href='https://www.danielpovey.com/files/2018_icassp_xvectors.pdf' target='_blank'>📚 X-Vector paper</a>""</p>")examples = [["samples/cate_blanch.mp3", "samples/cate_blanch_2.mp3"],["samples/cate_blanch.mp3", "samples/cate_blanch_3.mp3"],["samples/cate_blanch_2.mp3", "samples/cate_blanch_3.mp3"],["samples/heath_ledger.mp3", "samples/heath_ledger_2.mp3"],["samples/cate_blanch.mp3", "samples/kirsten_dunst.wav"],]demo = gr.Interface(fn=similarity_fn,inputs=inputs,outputs=output,
2023-05-03T15:20:00Z
@freddyaboultonthanks; i’ll have to try converting your example from Interface to Blocks,…becausedespitemytryingto pass in strings, they arrive at the function being called as None instead of the string.This only happens whencache_examplesorrun_on_clickare enabled.  When those are disabled, then the string arrives correctly and the user can manually press the Submit button.Or perhaps the fact that I’m using the queue leads to unexpected behavior?
2023-05-03T15:39:27Z
@freddyaboultonI get similar behavior when I convert your example to Blocks:with gr.Blocks() as demo: 
 
    inputs = [
        gr.Audio(source="microphone", type="filepath", optional=True, label="Speaker #1"),
        gr.Audio(source="microphone", type="filepath", optional=True, label="Speaker #2"),
    ]
    output = gr.HTML(label="")

    examples = [
        #["samples/cate_blanch.mp3", "samples/cate_blanch_2.mp3"],  # I didn't have these files but you get the idea
        ["/content/metal_trap.wav","/content/metal_trap.wav",]
    ]
    gr.Examples( fn=similarity_fn, examples=examples, inputs=inputs,  outputs=output,
            run_on_click=True,   # <-----****RIGHT HERE. Enabling this causes None to arrive at the inputs when an example is clicked.
            )
    submit_btn = gr.Button("Submit")
    submit_btn.click(fn=similarity_fn, inputs=inputs, outputs=output)

if __name__ == "__main__":
    demo.launch()I noticethis GitHub Issueshows another user reporting a similar problem for Blocks.
2023-05-03T15:52:08Z
Ok we’ll look into it! Thank you@drscotthawley
2023-05-13T20:54:58Z
@freddyaboultonAny movement on this?