Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
|
| 9 |
+
# Obter a máscara da imagem
|
| 10 |
+
pillow_mask = pipe(image, return_mask=True)
|
| 11 |
+
|
| 12 |
+
# Aplicar máscara na imagem original
|
| 13 |
+
pillow_image = pipe(image)
|
| 14 |
+
|
| 15 |
+
return pillow_image
|
| 16 |
+
|
| 17 |
+
# Criar uma interface Gradio
|
| 18 |
+
app = gr.Interface(
|
| 19 |
+
fn=remove_background,
|
| 20 |
+
inputs=gr.components.Image(type="pil"),
|
| 21 |
+
outputs=gr.components.Image(type="pil", format="png"), # Especificar saída como PNG
|
| 22 |
+
title="Remoção de Background de Imagens",
|
| 23 |
+
description="Envie uma imagem e veja o background sendo removido automaticamente. A imagem resultante será no formato PNG."
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
if __name__ == "__main__":
|
| 27 |
+
app.launch(share=True)
|