Gradio: How to "Clear" everything w/ Blocks?

How can we clear everything on the page, the way the simple interface’s Clear button does it?

I tried adding a button and cycling through all elements and calling x.clear() on each one, but it either has no effect or I get errors. I’ve looked all over the docs but can only find an example of clearing a single Chatbot interface. I’ve got multiple audio inputs and text inputs, and such. With the simple interface the Clear button automatically worked. So… how do we implement that?


Hi @drscotthawley !

Returning None from an event as the value for a component has the same effect as the Clear button.

@freddyaboulton Thanks for your reply.
Ok, I just now tried None) 

but it had no effect: none of my elements (e.g. Audio inputs) cleared when i pressed the button. Could you please be more specific? Thanks

Here’s more of my code right now:

        inputs = [audio1, textprompt1, audio2, textprompt2, interp_slider, batch_slider,
                        cfg_slider, crossfade_secs, init_audio, init_str_slider]
        outputs = [output_audio, embed_plot]
        wrapper = partial(process_audio, device, verbose=verbose) , inputs=inputs, outputs=outputs) None ) 

Can try via outputs=outputs in the click method?

@freddyaboulton Sure. I had tried that earlier; None, outputs=outputs )

…but was and am still getting the error:

An event handler didn't receive enough output values (needed: 2, received: 1). Wanted outputs: [audio, plot] Received outputs: [None]

Oh, perhpas I need to do lambda: [None]*2? …that hadn’t occurred to me.

Ok that works!
… but when I try it on my Slider items, rather than being restored to their default values, they all get moved all the way to the left. Is there a way to have them reset to the default (“value”) i specified when I setup the Sliders?

Yep - needs to be None for each component!

Yes, if you store the default variable in SLIDER_DEFAULT, return that instead of None. So if it’s the second element of outputs, do something like [None, 5], outputs=[Audio, Slider])

Thank you! All done! :slight_smile: