# Blocks as output

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fblocks-as-output%2F47432%3E%5C
**Category:** 🔒 Gradio\
**Created:** [July 20, 2023, 6:01am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fblocks-as-output%2F47432 "2023-07-20T06:01:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sachin](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/sachin/32/26534_2.png) [@sachin](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fsachin)%5C
**Post date:** [July 20, 2023, 6:01am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fblocks-as-output%2F47432%2F1 "2023-07-20T06:01:44Z")

</div>

I wish to plot k images (upto 9) in a 3x3 grid. I have figured out how to plot in the 3x3 grid using `gr.Blocks`, however I do not know how to make this part of a gradio interface. How do I fix the following:

```python
def get_sampled_images(k: int):
    sample_images = [Image.fromarray(np.random.randint(0, 255, (100, 100)).astype('uint8')) for _ in range(k)]
    sample_titles = [f"Image {i+1}" for i in range(k)]

    return sample_images, sample_titles

def plot_images(k: int):
    sample_images, sample_titles = get_sampled_images(int(k))
    batch_size = 3
    with gr.Blocks() as blocks:
        for i in range(0, len(sample_images), batch_size):
            with gr.Row():
                j = i
                while j < len(sample_images) and j < i + batch_size:
                    image = gr.Image(sample_images[j], label=sample_titles[j])
                    j += 1
                    
    return blocks
            
demo = gr.Interface(fn=plot_images, inputs="text", outputs=gr.Blocks)
demo.launch()

```

Note that the following does work,

```python
demo = plot_images(8)
demo.launch()

```
