gokaygokay commited on
Commit
e2763db
1 Parent(s): d8de5c1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -20
app.py CHANGED
@@ -224,25 +224,44 @@ def blend_images(bg_img, obj_img, mask_img, method):
224
 
225
  return (blend_img * 255).astype(np.uint8)
226
 
227
- examples = [
228
- ["img1.jpg", "img2.jpg", "mask1.jpg", "Poisson"],
229
- ["img3.jpg", "img4.jpg", "mask2.jpg", "Mixed Gradient"],
230
- ["img6.jpg", "img9.jpg", "mask3.jpg", "Laplacian"]
231
- ]
232
-
233
- iface = gr.Interface(
234
- fn=blend_images,
235
- inputs=[
236
- gr.Image(label="Background Image", type="numpy"),
237
- gr.Image(label="Object Image", type="numpy"),
238
- gr.Image(label="Mask Image", type="numpy"),
239
- gr.Radio(["Poisson", "Mixed Gradient", "Laplacian"], label="Blending Method")
240
- ],
241
- outputs=gr.Image(label="Blended Image"),
242
- title="Image Blending with Examples",
243
- description="Choose from example images or upload your own to blend using different methods.",
244
- examples=examples,
245
- cache_examples=True
246
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
247
 
248
  iface.launch()
 
224
 
225
  return (blend_img * 255).astype(np.uint8)
226
 
227
+ with gr.Blocks(theme='bethecloud/storj_theme') as iface:
228
+ gr.HTML("<h1>Image Blending with Multiple Methods</h1>")
229
+
230
+ with gr.Row():
231
+ with gr.Column():
232
+ bg_img = gr.Image(label="Background Image", type="numpy")
233
+ obj_img = gr.Image(label="Object Image", type="numpy")
234
+ with gr.Column():
235
+ mask_img = gr.ImageEditor(
236
+ label="Mask Image",
237
+ type="numpy",
238
+ brush=gr.Brush(colors=["#ffffff"], color_mode="fixed"),
239
+ eraser=gr.Eraser(),
240
+ height=300,
241
+ width=300,
242
+ )
243
+ method = gr.Radio(["Poisson", "Mixed Gradient", "Laplacian"], label="Blending Method", value="Poisson")
244
+
245
+ blend_button = gr.Button("Blend Images")
246
+
247
+ output_image = gr.Image(label="Blended Image")
248
+
249
+ blend_button.click(
250
+ blend_images,
251
+ inputs=[bg_img, obj_img, mask_img, method],
252
+ outputs=output_image
253
+ )
254
+
255
+ gr.Examples(
256
+ examples=[
257
+ ["img1.jpg", "img2.jpg", "mask1.jpg", "Poisson"],
258
+ ["img3.jpg", "img4.jpg", "mask2.jpg", "Mixed Gradient"],
259
+ ["img6.jpg", "img9.jpg", "mask3.jpg", "Laplacian"]
260
+ ],
261
+ inputs=[bg_img, obj_img, mask_img, method],
262
+ outputs=output_image,
263
+ fn=blend_images,
264
+ cache_examples=True,
265
+ )
266
 
267
  iface.launch()