Spaces:
Sleeping
Sleeping
Download app.py from lurivaljones/remove_background: direct link, hf CLI and curl.
- Browser
- Download file 977 Bytes
-
https://huggingface.co/spaces/lurivaljones/remove_background/resolve/main/app.py
- Command line
-
hf download hf://spaces/lurivaljones/remove_background/app.py
-
curl -L -o app.py https://huggingface.co/spaces/lurivaljones/remove_background/resolve/main/app.py
977 Bytes
| import gradio as gr | |
| from rembg import remove | |
| from PIL import Image | |
| import io | |
| import tempfile | |
| def remove_bg(image): | |
| img_bytes = io.BytesIO() | |
| image.save(img_bytes, format="PNG") | |
| output = remove(img_bytes.getvalue()) | |
| result = Image.open(io.BytesIO(output)) | |
| # cria arquivo temporário para download | |
| temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".png") | |
| result.save(temp_file.name) | |
| return result, temp_file.name | |
| with gr.Blocks() as demo: | |
| gr.Markdown("# 🖌️ Remove Background") | |
| gr.Markdown("Carregue sua imagem e baixe o PNG sem fundo com um clique.") | |
| with gr.Row(): | |
| with gr.Column(): | |
| inp = gr.Image(type="pil", label="Upload da Imagem") | |
| btn = gr.Button("Processar") | |
| with gr.Column(): | |
| out2 = gr.Image(type="pil", label="Sem Fundo") | |
| file_out = gr.File(label="Download PNG") | |
| btn.click(remove_bg, inputs=inp, outputs=[out2, file_out]) | |
| demo.launch() | |