Dynamical/Flexible output
HeyI wonder if there any way to make dynamical output.For example if my model found 3 audio then show 3 gr.outputs.Audio()
2022-05-20T02:15:37Z
Hi@Herde, yes this is possible using the newBlocks API:Basically the idea would be that you can have multiplegr.Audio()outputs, and for each output, you can  either use it to play audio or update itsvisibleproperty toFalseif you would like to hide it.Let me know if you have follow up questions!
2023-11-17T09:39:12Z
Hi@abidlabs, I have the same question, but with the documentation I am unable to implement it. Let’s say my model returns a variable number of images (as a list or a tuple of np.arrays) and I want the app to dynamically set the number of output blocks based on the model output’s length. I found on the website an example with a Slider:gradio.appControlling LayoutA Step-by-Step Gradio Tutorialbut I am stuck if I want to implement something similar with a button, because I have no access to the length of my output within the interface.Here is my (dummy) code, based on that example:max_outputs = 11

def variable_outputs(k):
    k = int(k)
    return[gr.Image(visible=True)]*k + [gr.Image(visible=False)] * (max_outputs - k)

def predict(img):
    return [img, ~img, img]

with gr.Blocks() as demo:
    with gr.Row():
        img_input = gr.Image()
        out_boxes = []
        for i in range(max_outputs):
            out_box = gr.Image()
            out_boxes.append(out_box)
        
    gr.Button("Predict").click(predict, inputs=img_input, outputs=variable_outputs(len(out_func)))Not surprisingly, this code raises the errorTypeError: object of type 'function' has no len()How can I have access to the output’s length during or after the click on the button?