A simple flask app to remove the background of an image with Rembg
Based on the tutorial on YouTube
There are several ways to run this application. No matter which of the options chosen from below. No matter which running option you have selected. The application will be accessibile via the browser on http://localhost:5100
You can also pull the prebuilt images from GitHub container repository. This is the recommended method, as you can easily integrate this container in your workflows (i.e., if you want to use it with other container in a docker compose
script).
- Pull the latest version of the container:
docker pull ghcr.io/eerikas/rembg-web-app:latest
- Run the Docker container:
docker run -p 5100:5100 ghcr.io/eerikas/rembg-web-app:latest
Note: Currently the Docker container image supports amd64
and arm64
architectures.
Alternatively you can use Docker to run the application from source code. For this method to work you need to have Docker
installed.
In the examples below the container is going to be named rembg-web
. Feel free to to chose the different name in your deployment.
- Clone the repository
- Build the Docker image:
docker build -t rembg-web .
- Run the created Docker container:
docker run -p 5100:5100 rembg-web
You can run the application using your local python
installation. To run the app perform the following steps:
- Clone the repository
- (Optional) Set up virtual environment.
python -m venv env source env/bin/activate
- Install requirements
pip install -r requirements.txt
- Run the application
You will need to wait until you see the following message in the console:
python app/app.py
* Serving Flask app 'app' * Debug mode: off WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. * Running on all addresses (0.0.0.0) * Running on http://127.0.0.1:5100
NOTE: If you are using this method, you will also need to download the u2net.onnx
model for background removal to work. This will be done automatically when uploading image for the first time. The model will be saved in <your-user-directory>/.u2net/u2net.onnx
It is generally recommended to run services like this behind a reverse proxy. Betlow is an example of docker-compose.yml
file of how this could be done by using Traefik reverse proxy.
By following this example the background remover would available at http://localhost
version: '3.9'
services:
web-app:
image: ghcr.io/eerikas/rembg-web-app:latest
labels:
- "traefik.enable=true"
- "traefik.http.routers.web-app.rule=Host(`localhost`)"
- "traefik.http.services.web-app.loadbalancer.server.port=5100"
traefik:
image: traefik:v2.9
container_name: traefik
command:
- "--api.insecure=true"
- "--providers.docker=true"
- "--entrypoints.web.address=:80"
ports:
- "80:80"
- "8080:8080" # Traefik Dashboard
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"