Spaces:
Build error
Build error
Download app.py from VicAllvex/removeBackground: direct link, hf CLI and curl.
- Browser
- Download file 1 kB
-
https://huggingface.co/spaces/VicAllvex/removeBackground/resolve/main/app.py
- Command line
-
hf download hf://spaces/VicAllvex/removeBackground/app.py
-
curl -L -o app.py https://huggingface.co/spaces/VicAllvex/removeBackground/resolve/main/app.py
1 kB
| import gradio as gr | |
| from transformers import pipeline | |
| from PIL import Image | |
| # função de remoção do background das imagens | |
| def remove_background(image): | |
| pipe = pipeline('image-segmentation', model="briaai/RMBG-1.4", trust_remote_code=True) | |
| pillow_mask = pipe(image, return_mask = True) # outputs a pillow mask | |
| pillow_image = pipe(image) # applies mask on input and returns a pillow image | |
| return pillow_image | |
| # criação da interface pelo gradio | |
| 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 removido automaticamente. A imagem resultante será no formato PNG.' | |
| ) | |
| # define que aplicação será executado neste módulo | |
| # prática: sempre utilizar este if | |
| if __name__ == "__main__": | |
| # executa a aplicação (share True: gera link compartilhável) | |
| app.launch(share=True) |