0

I want to be able to clear the input with gradio at the end of completing the inference without any additional click from the user. Currently with live=True, the inference function is triggered when the recording is stopped.

Here is the relevant part of my code:

audio_input = gr.Audio(source="microphone", type="filepath")
demo = gr.Interface(
    fn=inference, 
    inputs=audio_input,
    outputs="text",
    live=True
)
demo.launch()
  • I tried re-initializing the audio component at the end of my inference function. That didn't change anything
  • I looked through the docs related to components and all examples I found for other components and couldn't find anything to do this.
Corey
  • 170
  • 2
  • 11

1 Answers1

0

Solution 1

Found on Gradio doc for image component but there is also mention of audio component.

def clear():
  audio_input.clear()

clear_btn = gr.Button(value="Clear")
clear_btn.click(clear, [], [])

Gradio docs

solution 2

def clear():
  return None

clear_btn = gr.Button(value="Clear")
clear_btn.click(clear, inputs=[], outputs=[audio_input])