JZanataNeto commited on
Commit
bb5b545
·
verified ·
1 Parent(s): c3b5c6b

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+ from PIL import Image
4
+
5
+ def remove_background(image):
6
+ pipe = pipeline("image-segmentation", model="briaai/RMBG-1.4", trust_remote_code=True)
7
+
8
+ # Obter a máscara da imagem
9
+ pillow_mask = pipe(image, return_mask=True)
10
+
11
+ # Aplicar máscara na imagem original
12
+ pillow_image = pipe(image)
13
+
14
+ return pillow_image
15
+
16
+ app = gr.Interface(
17
+ fn=remove_background,
18
+ inputs=gr.components.Image(type="pil"),
19
+ outputs=gr.components.Image(type="pil", format="png"), # Especificar saída como PNG
20
+ title="Remoção de Background de Imagens",
21
+ description="Envie uma imagem e veja o background sendo removido automaticamente. A imagem resultante será no formato PNG."
22
+ )
23
+
24
+ if __name__ == "__main__":
25
+ app.launch(share=True)