--- title: BiRefNet Background Remover emoji: ✂️ colorFrom: indigo colorTo: purple sdk: gradio sdk_version: 5.45.0 app_file: app.py pinned: false license: mit short_description: Remove image backgrounds with BiRefNet. --- # BiRefNet Background Remover A small Gradio app that creates transparent PNG cut-outs with [BiRefNet-General](https://github.com/ZhengPeng7/BiRefNet), through [rembg](https://github.com/danielgatis/rembg). It replaces the previous RMBG-2.0/Transformers implementation. ## Run locally Requires Python 3.10 or newer. ```bash python -m venv .venv # Windows PowerShell .venv\Scripts\Activate.ps1 pip install -r requirements.txt python app.py ``` Open the local URL printed by Gradio. The first removal downloads the `birefnet-general` ONNX weights and caches them; later requests reuse the same in-process session. To choose a persistent cache location, set `REMBG_HOME` before starting the app. ## Deploy to Hugging Face Spaces 1. Create a new **Gradio** Space, preferably with Python 3.10+. 2. Push these files to the root of the Space: `app.py`, `remove_background.py`, `requirements.txt`, `README.md`, and `LICENSE`. 3. Wait for the build to finish. No secrets or manual model download are required. The model downloads automatically on the first inference. 4. For quicker or more reliable cold starts, use a persistent-storage upgrade and set `REMBG_HOME=/data/rembg` in the Space variables. This is optional; the default cache also works but is recreated after a free Space restarts. The app queues one request at a time to keep memory usage safe. It supports Hugging Face ZeroGPU and requests a GPU only while removing a background; a CPU Space also works, albeit more slowly. ## Licensing and attribution This repository's code is MIT licensed. BiRefNet's upstream repository is MIT licensed, and `rembg` is MIT licensed. The selected `birefnet-general` model is the BiRefNet general-use ONNX model distributed by `rembg`; unlike the prior BRIA RMBG-2.0 model, it is intended here to support commercial use. Keep this attribution and independently review upstream model and dataset terms for your specific deployment. Links: [BiRefNet](https://github.com/ZhengPeng7/BiRefNet) · [rembg model list](https://github.com/danielgatis/rembg#available-models)