Update app.py
Browse files1 unmodified line23456789101112131415161718192030 unmodified lines5152535455565758596061626364651 unmodified linefrom PIL import Image# Function to process and display the images in grid formatdef create_collage(uploaded_files, grid_layout):# Open imagesimages = [Image.open(file.name) for file in uploaded_files]# Determine grid dimensions based on layoutif grid_layout == "1x2":rows, cols = 1, 2elif grid_layout == "1x3":rows, cols = 1, 3elif grid_layout == "2x2":rows, cols = 2, 2elif grid_layout == "2x3":rows, cols = 2, 3# Create a blank canvas for the collage without spacingcollage_width = max(img.width for img in images) * cols30 unmodified linesvalue="1x2" # Default value)# Step 3: Display preview of the gridoutput = gr.Image(label="Collage Preview")# Step 4: Process the images when files are uploaded or grid layout is selecteduploaded_files.change(create_collage, inputs=[uploaded_files, grid_layout], outputs=output)grid_layout.change(create_collage, inputs=[uploaded_files, grid_layout], outputs=output)# Step 5: Download button for the final collagedownload_button = gr.Button("Download Collage")download_button.click(create_collage, inputs=[uploaded_files, grid_layout], outputs=output)app.launch(share=True) # Public link to share the app1 unmodified line23456789101112131415161718192021222324252630 unmodified lines575859606162636465666768697071727374757677787980818283848586871 unmodified linefrom PIL import Image# Function to process and display the images in grid formatdef create_collage(uploaded_files, grid_layout, orientation):# Open imagesimages = [Image.open(file.name) for file in uploaded_files]# Determine grid dimensions and orientationif grid_layout == "1x2":rows, cols = 1, 2elif grid_layout == "1x3":rows, cols = 1, 3elif grid_layout == "2x2":if orientation == "Vertical":rows, cols = 2, 2 # Vertical layoutelse:rows, cols = 1, 4 # Horizontal layout (single row)elif grid_layout == "2x3":if orientation == "Vertical":rows, cols = 2, 3 # Vertical layoutelse:rows, cols = 1, 6 # Horizontal layout (single row)# Create a blank canvas for the collage without spacingcollage_width = max(img.width for img in images) * cols30 unmodified linesvalue="1x2" # Default value)# Step 3: Orientation selection for 2x2 and 2x3orientation = gr.Radio(choices=["Vertical", "Horizontal"],label="Select Orientation",value="Vertical", # Default valuevisible=False # Initially hidden, will only show for 2x2 and 2x3)# Show orientation options only when grid layout is 2x2 or 2x3grid_layout.change(lambda layout: gr.update(visible=layout in ["2x2", "2x3"]),inputs=[grid_layout],outputs=[orientation])# Step 4: Display preview of the gridoutput = gr.Image(label="Collage Preview")# Step 5: Process the images when files are uploaded or grid layout is selecteduploaded_files.change(create_collage, inputs=[uploaded_files, grid_layout, orientation], outputs=output)grid_layout.change(create_collage, inputs=[uploaded_files, grid_layout, orientation], outputs=output)orientation.change(create_collage, inputs=[uploaded_files, grid_layout, orientation], outputs=output)# Step 6: Download button for the final collagedownload_button = gr.Button("Download Collage")download_button.click(create_collage, inputs=[uploaded_files, grid_layout, orientation], outputs=output)app.launch(share=True) # Public link to share the app
app.py+32-10