# Dynamical/Flexible output

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fdynamical-flexible-output%2F18146%3E%5C
**Category:** 🔒 Gradio\
**Created:** [May 19, 2022, 11:38am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fdynamical-flexible-output%2F18146 "2022-05-19T11:38:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Herdre](https://avatars.discourse-cdn.com/v4/letter/h/e68b1a/32.png) [@Herdre](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FHerdre)%5C
**Post date:** [May 19, 2022, 11:38am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fdynamical-flexible-output%2F18146%2F1 "2022-05-19T11:38:16Z")

</div>

Hey 👋  
I wonder if there any way to make dynamical output.  
For example if my model found 3 audio then show 3 gr.outputs.Audio()

---

<div class="post-metadata">

**Author:** ![abidlabs](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/abidlabs/32/21878_2.png) [@abidlabs](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fabidlabs)%5C
**Post date:** [May 20, 2022, 2:15am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fdynamical-flexible-output%2F18146%2F2 "2022-05-20T02:15:37Z")

</div>

Hi @Herde, yes this is possible using the new [Blocks API](https://www.gradio.app/docs/#blocks):

Basically the idea would be that you can have multiple `gr.Audio()` outputs, and for each output, you can either use it to play audio or update its `visible` property to `False` if you would like to hide it.

Let me know if you have follow up questions!

---

<div class="post-metadata">

**Author:** ![noe-mi](https://avatars.discourse-cdn.com/v4/letter/n/97f17d/32.png) [@noe-mi](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fnoe-mi)%5C
**Post date:** [November 17, 2023, 9:39am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fdynamical-flexible-output%2F18146%2F6 "2023-11-17T09:39:12Z")

</div>

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:

> **[Controlling Layout](https://www.gradio.app/guides/controlling-layout)**
>
> A Step-by-Step Gradio Tutorial

but 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:

```auto
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 error

```auto
TypeError: 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?
