LPX55 commited on
Commit
7c1408f
·
verified ·
1 Parent(s): 066f283

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -7
app.py CHANGED
@@ -4,12 +4,12 @@ import zipfile
4
  from io import BytesIO
5
  from PIL import Image
6
 
7
- def split_image_grid(image, grid_size):
8
  # Convert the image to a NumPy array
9
  img = np.array(image)
10
  width, height = img.shape[1], img.shape[0]
11
- grid_width, grid_height = grid_size
12
-
13
  # Calculate the size of each grid cell
14
  cell_width = width // grid_width
15
  cell_height = height // grid_height
@@ -42,9 +42,9 @@ def zip_images(images):
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
@@ -52,10 +52,11 @@ def process_image(image, grid_size):
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)
 
4
  from io import BytesIO
5
  from PIL import Image
6
 
7
+ def split_image_grid(image, grid_cols, grid_rows):
8
  # Convert the image to a NumPy array
9
  img = np.array(image)
10
  width, height = img.shape[1], img.shape[0]
11
+ grid_width = grid_cols
12
+ grid_height = grid_rows
13
  # Calculate the size of each grid cell
14
  cell_width = width // grid_width
15
  cell_height = height // grid_height
 
42
  zip_buffer.seek(0)
43
  return zip_buffer
44
 
45
+ def process_image(image, grid_cols_input, grid_rows_input):
46
  # Split the image into a grid of frames
47
+ frames = split_image_grid(image, grid_cols_input, grid_rows_input)
48
  # Zip the frames into a single zip file
49
  zip_file = zip_images(frames)
50
  return zip_file
 
52
  with gr.Blocks() as demo:
53
  with gr.Row():
54
  image_input = gr.Image(label="Input Image")
55
+ grid_cols_input = gr.Slider(1, 10, value=2, step=1, label="Grid Cols")
56
+ grid_rows_input = gr.Slider(1, 10, value=2, step=1, label="Grid Rows")
57
  zip_output = gr.File(label="Output Zip File")
58
  process_button = gr.Button("Process Image")
59
 
60
+ process_button.click(process_image, inputs=[image_input, grid_cols_input, grid_rows_input], outputs=zip_output)
61
 
62
  demo.launch(show_error=True)