Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,30 +1,30 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
from transformers import pipeline
|
| 3 |
-
from PIL import Image
|
| 4 |
-
|
| 5 |
-
# Função para remover o background da imagem
|
| 6 |
-
def remove_background(image):
|
| 7 |
-
pipe = pipeline("image-segmentation", model="briaai/RMBG-1.4", trust_remote_code=True)
|
| 8 |
-
# Obter a máscara da imagem
|
| 9 |
-
segmentation = pipe(image)
|
| 10 |
-
# Aplicar a máscara para remover o fundo
|
| 11 |
-
# Filtrando a parte da segmentação onde a label é "person" ou qualquer outra desejada
|
| 12 |
-
mask = Image.fromarray(segmentation[0]['mask']) # Segmentação com maior probabilidade
|
| 13 |
-
original_image = Image.fromarray(image)
|
| 14 |
-
|
| 15 |
-
# Remover fundo
|
| 16 |
-
output = Image.composite(original_image, Image.new("RGBA", original_image.size), mask)
|
| 17 |
-
return output
|
| 18 |
-
|
| 19 |
-
# Criar a interface Gradio
|
| 20 |
-
app = gr.Interface(
|
| 21 |
-
fn=remove_background,
|
| 22 |
-
inputs=gr.Image(type="pil"),
|
| 23 |
-
outputs=gr.Image(type="pil"
|
| 24 |
-
title="Remoção de Background de Imagens",
|
| 25 |
-
description="Envie uma imagem e veja o background sendo removido automaticamente.
|
| 26 |
-
)
|
| 27 |
-
|
| 28 |
-
# Executar a aplicação
|
| 29 |
-
if __name__ == "__main__":
|
| 30 |
-
app.launch(share=True)
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
from PIL import Image
|
| 4 |
+
|
| 5 |
+
# Função para remover o background da imagem
|
| 6 |
+
def remove_background(image):
|
| 7 |
+
pipe = pipeline("image-segmentation", model="briaai/RMBG-1.4", trust_remote_code=True)
|
| 8 |
+
# Obter a máscara da imagem
|
| 9 |
+
segmentation = pipe(image)
|
| 10 |
+
# Aplicar a máscara para remover o fundo
|
| 11 |
+
# Filtrando a parte da segmentação onde a label é "person" ou qualquer outra desejada
|
| 12 |
+
mask = Image.fromarray(segmentation[0]['mask']) # Segmentação com maior probabilidade
|
| 13 |
+
original_image = Image.fromarray(image)
|
| 14 |
+
|
| 15 |
+
# Remover fundo
|
| 16 |
+
output = Image.composite(original_image, Image.new("RGBA", original_image.size), mask)
|
| 17 |
+
return output
|
| 18 |
+
|
| 19 |
+
# Criar a interface Gradio
|
| 20 |
+
app = gr.Interface(
|
| 21 |
+
fn=remove_background,
|
| 22 |
+
inputs=gr.Image(type="pil"),
|
| 23 |
+
outputs=gr.Image(type="pil"),
|
| 24 |
+
title="Remoção de Background de Imagens",
|
| 25 |
+
description="Envie uma imagem e veja o background sendo removido automaticamente."
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
# Executar a aplicação
|
| 29 |
+
if __name__ == "__main__":
|
| 30 |
+
app.launch(share=True)
|