Update app.py
Browse files
app.py
CHANGED
@@ -34,7 +34,7 @@ def zip_images(images):
|
|
34 |
for idx, img in enumerate(images):
|
35 |
# Save each image to the zip file
|
36 |
img_buffer = BytesIO()
|
37 |
-
img = Image.fromarray(img)
|
38 |
img.save(img_buffer, format='PNG')
|
39 |
img_buffer.seek(0)
|
40 |
zipf.writestr(f'image_{idx}.png', img_buffer.getvalue())
|
@@ -42,20 +42,20 @@ def zip_images(images):
|
|
42 |
zip_buffer.seek(0)
|
43 |
return zip_buffer
|
44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
with gr.Blocks() as demo:
|
46 |
with gr.Row():
|
47 |
image_input = gr.Image(label="Input Image")
|
48 |
grid_size_input = gr.Slider(1, 10, value=2, step=1, label="Grid Size")
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
def process_image(image, grid_size):
|
53 |
-
# Split the image into a grid of frames
|
54 |
-
frames = split_image_grid(image, (grid_size, grid_size))
|
55 |
-
# Zip the frames into a single file
|
56 |
-
zip_file = zip_images(frames)
|
57 |
-
return zip_file
|
58 |
|
59 |
-
|
60 |
|
61 |
demo.launch(show_error=True)
|
|
|
34 |
for idx, img in enumerate(images):
|
35 |
# Save each image to the zip file
|
36 |
img_buffer = BytesIO()
|
37 |
+
img = Image.fromarray(img) # Convert NumPy array to PIL Image
|
38 |
img.save(img_buffer, format='PNG')
|
39 |
img_buffer.seek(0)
|
40 |
zipf.writestr(f'image_{idx}.png', img_buffer.getvalue())
|
|
|
42 |
zip_buffer.seek(0)
|
43 |
return zip_buffer
|
44 |
|
45 |
+
def process_image(image, grid_size):
|
46 |
+
# Split the image into a grid of frames
|
47 |
+
frames = split_image_grid(image, grid_size)
|
48 |
+
# Zip the frames into a single zip file
|
49 |
+
zip_file = zip_images(frames)
|
50 |
+
return zip_file
|
51 |
+
|
52 |
with gr.Blocks() as demo:
|
53 |
with gr.Row():
|
54 |
image_input = gr.Image(label="Input Image")
|
55 |
grid_size_input = gr.Slider(1, 10, value=2, step=1, label="Grid Size")
|
56 |
+
zip_output = gr.File(label="Output Zip File")
|
57 |
+
process_button = gr.Button("Process Image")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
|
59 |
+
process_button.click(process_image, inputs=[image_input, grid_size_input], outputs=zip_output)
|
60 |
|
61 |
demo.launch(show_error=True)
|