Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -4,20 +4,29 @@ import zipfile
|
|
4 |
from PIL import Image
|
5 |
import tempfile
|
6 |
|
7 |
-
def
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
return "image.zip"
|
17 |
-
|
18 |
-
gr.Interface(fn=
|
19 |
inputs="image",
|
20 |
outputs="file",
|
21 |
-
title="
|
22 |
examples = ["example.jpg"]
|
23 |
).launch();
|
|
|
4 |
from PIL import Image
|
5 |
import tempfile
|
6 |
|
7 |
+
def split_image(image):
|
8 |
+
im = Image.fromarray(np.uint8(image))
|
9 |
+
|
10 |
+
# Obtiene las dimensiones de la imagen
|
11 |
+
width, height = im.size
|
12 |
+
|
13 |
+
# Divide la imagen en 9 imágenes más pequeñas
|
14 |
+
for i in range(3):
|
15 |
+
for j in range(3):
|
16 |
+
box = (j*width/3, i*height/3, (j+1)*width/3, (i+1)*height/3)
|
17 |
+
region = im.crop(box)
|
18 |
+
region = region.convert("RGB")
|
19 |
+
region = region.resize((512, 512), Image.ANTIALIAS)
|
20 |
+
|
21 |
+
with tempfile.NamedTemporaryFile(suffix='.jpg') as temp:
|
22 |
+
region.save(temp.name)
|
23 |
+
with zipfile.ZipFile("image.zip", 'w') as zip:
|
24 |
+
zip.write(temp.name)
|
25 |
return "image.zip"
|
26 |
+
|
27 |
+
gr.Interface(fn=split_image,
|
28 |
inputs="image",
|
29 |
outputs="file",
|
30 |
+
title="Convert collage to images",
|
31 |
examples = ["example.jpg"]
|
32 |
).launch();
|