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?
Thanks.
1 Like
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
clear_btn.click(lambda: 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)
submit_btn.click(fn=wrapper, inputs=inputs, outputs=outputs)
clear_btn.click(lambda: None )
Can try via outputs=outputs
in the click
method?
@freddyaboulton Sure. I had tried that earlier; clear_btn.click(lambda: 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 clear_btn.click(lambda: [None, 5], outputs=[Audio, Slider])
1 Like