File size: 1,500 Bytes
a990237
 
b07ba1d
a990237
 
 
b07ba1d
a990237
 
 
 
 
b07ba1d
 
 
 
 
a990237
 
b07ba1d
 
 
 
 
a990237
 
 
b07ba1d
 
 
 
 
 
a990237
 
aae25ae
b07ba1d
 
a990237
 
 
 
b07ba1d
a990237
b07ba1d
a990237
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import gradio as gr
import os
import shutil
from generate import create_multiple_large_images

BASE_PATH = "./generated_images/"
ZIP_PATH = "./generated_images.zip"

def generate_images(size_mb, num_images):
    if not os.path.exists(BASE_PATH):
        os.makedirs(BASE_PATH)

    for filename in os.listdir(BASE_PATH):
        file_path = os.path.join(BASE_PATH, filename)
        if os.path.isfile(file_path):
            os.unlink(file_path)

    created_image_paths = create_multiple_large_images(BASE_PATH, size_mb, num_images)

    if os.path.exists(ZIP_PATH):
        os.remove(ZIP_PATH)
    shutil.make_archive("generated_images", 'zip', BASE_PATH)

    return created_image_paths, ZIP_PATH

def create_ui():
    with gr.Blocks() as demo:
        gr.Markdown("# Test Image Generator")

        with gr.Row():
            size_input = gr.Slider(minimum=1, maximum=100, label="Target size of the images in MB")
            num_images_input = gr.Slider(minimum=1, maximum=100, step=1, label="Number of images to generate")

        generate_button = gr.Button("Generate")

        output_gallery = gr.Gallery(label="Generated Images", columns=3, height='400px')
        download_button = gr.File(label="Download All Images as ZIP")


        generate_button.click(
            fn=generate_images,
            inputs=[size_input, num_images_input],
            outputs=[output_gallery, download_button]
        )

    return demo

if __name__ == "__main__":
    ui = create_ui()
    ui.launch()