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:
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,
demo = plot_images(8)
demo.launch()