File size: 917 Bytes
0c2356c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# -*- coding: utf-8 -*-
"""InterfaceRemoveBackground.ipynb

Automatically generated by Colab.

Original file is located at
    https://colab.research.google.com/drive/1c2CqhHMVR1qncca5n-8l9MrF4SGk3cKa
"""

#!pip install gradio

import gradio as gr
from transformers import pipeline
from PIL import Image

def remove_background(image):
    pipe = pipeline("image-segmentation",model="briaai/RMBG-1.4",trust_remote_code=True)
    pillow_mask = pipe(image,return_mask=True  )
    pillow_image = pipe(image)
    return pillow_image

app = gr.Interface(
    fn=remove_background,
    inputs=gr.components.Image(type="pil"),
    outputs=gr.components.Image(type="pil",format="png"),
    title="Remoção de Background de Imagens",
        description="Envie uma imagem e veja o background sendo removido automaticamente. A imagem resultante será no formato PNG."

)

if __name__ == "__main__":
    app.launch(share=True)