Update app.py
Browse files
app.py
CHANGED
@@ -5,11 +5,6 @@ from PIL import Image
|
|
5 |
import zipfile
|
6 |
import os
|
7 |
|
8 |
-
class NamedBytesIO(BytesIO):
|
9 |
-
def __init__(self, *args, name="output.zip", **kwargs):
|
10 |
-
super(NamedBytesIO, self).__init__(*args, **kwargs)
|
11 |
-
self.name = name
|
12 |
-
|
13 |
def split_image_grid(image, grid_cols, grid_rows):
|
14 |
if isinstance(image, np.ndarray):
|
15 |
image = Image.fromarray(image)
|
@@ -29,7 +24,7 @@ def split_image_grid(image, grid_cols, grid_rows):
|
|
29 |
return frames
|
30 |
|
31 |
def zip_images(images):
|
32 |
-
zip_buffer =
|
33 |
with zipfile.ZipFile(zip_buffer, 'w') as zipf:
|
34 |
for idx, img in enumerate(images):
|
35 |
img_buffer = BytesIO()
|
@@ -38,14 +33,14 @@ def zip_images(images):
|
|
38 |
img_buffer.seek(0)
|
39 |
zipf.writestr(f'image_{idx}.png', img_buffer.getvalue())
|
40 |
zip_buffer.seek(0)
|
41 |
-
return zip_buffer
|
42 |
|
43 |
def create_gif(images):
|
44 |
-
gif_buffer =
|
45 |
images_pil = [Image.fromarray(img) for img in images]
|
46 |
images_pil[0].save(gif_buffer, format='GIF', save_all=True, append_images=images_pil[1:], duration=100, loop=0)
|
47 |
gif_buffer.seek(0)
|
48 |
-
return gif_buffer
|
49 |
|
50 |
def process_image(image, grid_cols_input, grid_rows_input):
|
51 |
frames = split_image_grid(image, grid_cols_input, grid_rows_input)
|
|
|
5 |
import zipfile
|
6 |
import os
|
7 |
|
|
|
|
|
|
|
|
|
|
|
8 |
def split_image_grid(image, grid_cols, grid_rows):
|
9 |
if isinstance(image, np.ndarray):
|
10 |
image = Image.fromarray(image)
|
|
|
24 |
return frames
|
25 |
|
26 |
def zip_images(images):
|
27 |
+
zip_buffer = BytesIO()
|
28 |
with zipfile.ZipFile(zip_buffer, 'w') as zipf:
|
29 |
for idx, img in enumerate(images):
|
30 |
img_buffer = BytesIO()
|
|
|
33 |
img_buffer.seek(0)
|
34 |
zipf.writestr(f'image_{idx}.png', img_buffer.getvalue())
|
35 |
zip_buffer.seek(0)
|
36 |
+
return {"name": "output.zip", "data": zip_buffer.getvalue()}
|
37 |
|
38 |
def create_gif(images):
|
39 |
+
gif_buffer = BytesIO()
|
40 |
images_pil = [Image.fromarray(img) for img in images]
|
41 |
images_pil[0].save(gif_buffer, format='GIF', save_all=True, append_images=images_pil[1:], duration=100, loop=0)
|
42 |
gif_buffer.seek(0)
|
43 |
+
return {"name": "output.gif", "data": gif_buffer.getvalue()}
|
44 |
|
45 |
def process_image(image, grid_cols_input, grid_rows_input):
|
46 |
frames = split_image_grid(image, grid_cols_input, grid_rows_input)
|