File size: 938 Bytes
bef4046
 
 
22a1271
bef4046
 
22a1271
 
 
 
 
 
 
 
 
 
 
bef4046
 
22a1271
 
 
 
 
bef4046
15028e0
22a1271
15028e0
22a1271
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
import gradio as gr
from transformers import pipeline
from PIL import Image

# Função para remover o background da imagem
def remove_background(image):
    # Inicializar o pipeline de segmentação de imagem
    pipe = pipeline("image-segmentation", model="briaai/RMBG-1.4", trust_remote_code=True)
    
    # Obter a máscara da imagem
    pillow_mask = pipe(image, return_mask=True)
    
    # Aplicar máscara na imagem original
    pillow_image = pipe(image)
    
    return pillow_image

# Criar uma interface Gradio
app = gr.Interface(
    fn=remove_background,
    inputs=gr.Image(type="pil"),
    outputs=gr.Image(type="pil", format="png"),  # Especificar saída como 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."
)

# Iniciar a interface
if __name__ == "__main__":
    app.launch(share=True)