cr8 commited on
Commit
daa5ede
·
verified ·
1 Parent(s): 2d79e4f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -7
app.py CHANGED
@@ -24,10 +24,9 @@ def create_collage(uploaded_files, grid_layout):
24
  # Resize images to fit the grid
25
  resized_images = []
26
  for img in images:
27
- # Resize or crop image to fit the grid cell size
28
  img_width = collage_width // cols
29
  img_height = collage_height // rows
30
- img_resized = img.resize((img_width, img_height), Image.Resampling.LANCZOS) # Resize to fit
31
  resized_images.append(img_resized)
32
 
33
  # Place images on the canvas in grid format without spacing
@@ -41,24 +40,28 @@ def create_collage(uploaded_files, grid_layout):
41
  # Gradio Interface
42
  with gr.Blocks() as app:
43
  with gr.Column():
44
- # Step 1: File upload for multiple images
 
 
 
 
45
  uploaded_files = gr.Files(label="Upload Images", file_count="multiple", file_types=["image"])
46
 
47
- # Step 2: Grid selection
48
  grid_layout = gr.Radio(
49
  choices=["1x2", "1x3", "2x2", "2x3"],
50
  label="Select Grid Layout",
51
  value="1x2" # Default value
52
  )
53
 
54
- # Step 3: Display preview of the grid
55
  output = gr.Image(label="Collage Preview")
56
 
57
- # Step 4: Process the images when files are uploaded or grid layout is selected
58
  uploaded_files.change(create_collage, inputs=[uploaded_files, grid_layout], outputs=output)
59
  grid_layout.change(create_collage, inputs=[uploaded_files, grid_layout], outputs=output)
60
 
61
- # Step 5: Download button for the final collage
62
  download_button = gr.Button("Download Collage")
63
  download_button.click(create_collage, inputs=[uploaded_files, grid_layout], outputs=output)
64
 
 
24
  # Resize images to fit the grid
25
  resized_images = []
26
  for img in images:
 
27
  img_width = collage_width // cols
28
  img_height = collage_height // rows
29
+ img_resized = img.resize((img_width, img_height), Image.Resampling.LANCZOS)
30
  resized_images.append(img_resized)
31
 
32
  # Place images on the canvas in grid format without spacing
 
40
  # Gradio Interface
41
  with gr.Blocks() as app:
42
  with gr.Column():
43
+ # Step 1: Title and description
44
+ gr.Markdown("# **Image Collage Maker**")
45
+ gr.Markdown("Create custom image collages with different grid layouts like 1x2, 1x3, 2x2, and 2x3. Upload your images and select a layout!")
46
+
47
+ # Step 2: File upload for multiple images
48
  uploaded_files = gr.Files(label="Upload Images", file_count="multiple", file_types=["image"])
49
 
50
+ # Step 3: Grid selection
51
  grid_layout = gr.Radio(
52
  choices=["1x2", "1x3", "2x2", "2x3"],
53
  label="Select Grid Layout",
54
  value="1x2" # Default value
55
  )
56
 
57
+ # Step 4: Display preview of the grid
58
  output = gr.Image(label="Collage Preview")
59
 
60
+ # Step 5: Process the images when files are uploaded or grid layout is selected
61
  uploaded_files.change(create_collage, inputs=[uploaded_files, grid_layout], outputs=output)
62
  grid_layout.change(create_collage, inputs=[uploaded_files, grid_layout], outputs=output)
63
 
64
+ # Step 6: Download button for the final collage
65
  download_button = gr.Button("Download Collage")
66
  download_button.click(create_collage, inputs=[uploaded_files, grid_layout], outputs=output)
67