Weaita commited on
Commit
f953e00
·
1 Parent(s): fef6a07

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -12
app.py CHANGED
@@ -4,20 +4,29 @@ import zipfile
4
  from PIL import Image
5
  import tempfile
6
 
7
- def flip_image(image):
8
- image = Image.fromarray(np.uint8(image))
9
- # Create a temporary file
10
- with tempfile.NamedTemporaryFile(suffix='.jpg') as temp:
11
- # Save the image to the temporary file
12
- image.save(temp.name)
13
- # Create zip file
14
- with zipfile.ZipFile("image.zip", 'w') as zip:
15
- zip.write(temp.name)
 
 
 
 
 
 
 
 
 
16
  return "image.zip"
17
-
18
- gr.Interface(fn=flip_image,
19
  inputs="image",
20
  outputs="file",
21
- title="Flip An Image Upside Down",
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();