Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from PIL import Image
|
|
|
|
| 3 |
|
| 4 |
# Function to process and display the images in grid format
|
| 5 |
def create_collage(uploaded_files, grid_layout):
|
|
@@ -35,7 +36,11 @@ def create_collage(uploaded_files, grid_layout):
|
|
| 35 |
col = i % cols
|
| 36 |
collage.paste(img, (col * img.width, row * img.height))
|
| 37 |
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
# Gradio Interface
|
| 41 |
with gr.Blocks() as app:
|
|
@@ -61,8 +66,8 @@ with gr.Blocks() as app:
|
|
| 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 |
|
| 68 |
app.launch(share=True) # Public link to share the app
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from PIL import Image
|
| 3 |
+
import io
|
| 4 |
|
| 5 |
# Function to process and display the images in grid format
|
| 6 |
def create_collage(uploaded_files, grid_layout):
|
|
|
|
| 36 |
col = i % cols
|
| 37 |
collage.paste(img, (col * img.width, row * img.height))
|
| 38 |
|
| 39 |
+
# Save the collage as a PNG file in memory
|
| 40 |
+
output_io = io.BytesIO()
|
| 41 |
+
collage.save(output_io, format="PNG")
|
| 42 |
+
output_io.seek(0) # Reset the pointer to the start of the file
|
| 43 |
+
return output_io
|
| 44 |
|
| 45 |
# Gradio Interface
|
| 46 |
with gr.Blocks() as app:
|
|
|
|
| 66 |
uploaded_files.change(create_collage, inputs=[uploaded_files, grid_layout], outputs=output)
|
| 67 |
grid_layout.change(create_collage, inputs=[uploaded_files, grid_layout], outputs=output)
|
| 68 |
|
| 69 |
+
# Step 6: Download button for the final collage as PNG
|
| 70 |
+
download_button = gr.Button("Download Collage (PNG)")
|
| 71 |
download_button.click(create_collage, inputs=[uploaded_files, grid_layout], outputs=output)
|
| 72 |
|
| 73 |
app.launch(share=True) # Public link to share the app
|