injet commited on
Commit
45f8da0
·
1 Parent(s): 0b3e3eb

add app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ from PIL import Image, ImageOps
4
+
5
+ root = os.path.dirname(os.path.abspath(__file__))
6
+ static = os.path.join(root, "static")
7
+
8
+ def save_mask(inputs):
9
+ layers = inputs['layers']
10
+ if not layers:
11
+ return inputs['background']
12
+ mask = layers[0]
13
+ new_image = Image.new('RGBA', mask.size, color='white')
14
+ new_image.paste(mask, mask=mask)
15
+ new_image = new_image.convert('RGB')
16
+ return ImageOps.invert(new_image)
17
+
18
+
19
+ ui = gr.Interface(
20
+ save_mask,
21
+ gr.ImageMask(type='pil'),
22
+ "image"
23
+ )
24
+
25
+ if __name__ == "__main__":
26
+ ui.launch(share=False)