我想创建一个界面gradio
我有一个最初隐藏的音频输入,经过一些步骤后,例如收到指令后,用户可以录制音频。但是当我使音频输入可见时,它无法录制。
import gradio
with gradio.Blocks() as interface:
recorder = gradio.Audio(source='microphone', type='filepath', visible=False)
action_btn = gradio.Button('Start')
def next_line(action):
if action == 'Start':
return {action_btn: 'Next', recorder: gradio.update(visible=True)}
else:
return {action_btn: 'Done', recorder: gradio.update(visible=False)}
action_btn.click(next_line, inputs=[action_btn], outputs=[action_btn, recorder])
interface.launch(share=True)
另外,我目前正在 jupyter 笔记本中使用它进行原型设计。
有人可以帮助我解决这个问题,使用有时隐藏的组件进行录制吗?
仅添加一个组件outputs
做到了interactive=False
默认情况下。
将您的音频组件添加到inputs
使其发挥作用:
import gradio
with gradio.Blocks() as interface:
recorder = gradio.Audio(source='microphone', type='filepath', visible=False)
action_btn = gradio.Button('Start')
def next_line(action, _):
if action == 'Start':
return {action_btn: 'Next', recorder: gradio.update(visible=True)}
else:
return {action_btn: 'Done', recorder: gradio.update(visible=False)}
action_btn.click(next_line, inputs=[action_btn, recorder], outputs=[action_btn, recorder])
interface.launch(share=True)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)