167AliRaza commited on
Commit
20ee1c0
·
verified ·
1 Parent(s): f9f4dfa

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from PIL import Image
2
+ import gradio as gr
3
+
4
+ def collage_images(img1, img2, layout="Horizontal"):
5
+ img1 = img1.convert("RGB")
6
+ img2 = img2.convert("RGB")
7
+
8
+ if layout == "Horizontal":
9
+ new_width = img1.width + img2.width
10
+ new_height = max(img1.height, img2.height)
11
+ collage = Image.new("RGB", (new_width, new_height), color=(255, 255, 255))
12
+ collage.paste(img1, (0, 0))
13
+ collage.paste(img2, (img1.width, 0))
14
+ else:
15
+ new_width = max(img1.width, img2.width)
16
+ new_height = img1.height + img2.height
17
+ collage = Image.new("RGB", (new_width, new_height), color=(255, 255, 255))
18
+ collage.paste(img1, (0, 0))
19
+ collage.paste(img2, (0, img1.height))
20
+
21
+ return collage
22
+
23
+ demo = gr.Interface(
24
+ fn=collage_images,
25
+ inputs=[
26
+ gr.Image(type="pil", label="First Image"),
27
+ gr.Image(type="pil", label="Second Image"),
28
+ gr.Radio(["Horizontal", "Vertical"], label="Layout")
29
+ ],
30
+ outputs=gr.Image(label="Collaged Image"),
31
+ title="Image Collage App",
32
+ description="Upload two images and choose layout direction (horizontal or vertical)."
33
+ )
34
+
35
+ if __name__ == "__main__":
36
+ demo.launch()