shemayons's picture
Upload 4 files
76b4917 verified
|
raw
history blame
2.79 kB
metadata
title: Background Removal Tool
emoji: πŸ‘€
colorFrom: blue
colorTo: blue
sdk: gradio
sdk_version: 5.12.0
app_file: app.py
pinned: false
short_description: A tool to remove image backgrounds with precision

Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference

Background Removal Tool

This is a deep learning-powered Background Removal Tool that uses image segmentation models to remove backgrounds from images and add transparency (alpha channel). It features a user-friendly interface built with Gradio to interact with the tool via image uploads, URLs, or file outputs.


Features

  1. Two Segmentation Models:
    • BiRefNet: Efficient and robust segmentation model.
    • RMBG-2.0: Advanced model for refined background removal.
  2. Multiple Input Methods:
    • Upload images directly from your system.
    • Provide an image URL for processing.
    • Upload and save the processed image as a PNG file with transparency.
  3. Customizable: Switch between models for different use cases.
  4. Fast and GPU-Powered: Leverages CUDA for faster processing on GPUs.

Requirements

  • Python 3.8+
  • A GPU-enabled environment for CUDA support (optional but recommended).
  • Installed Python libraries:
    • gradio
    • torch
    • transformers
    • torchvision
    • Pillow
    • numpy

Install dependencies using:

pip install gradio torch torchvision transformers Pillow numpy

Usage

Run the Application

Execute the script using:

python inference.py

Interface

Tab 1: Image Upload

  1. Upload an image from your local system.
  2. Select a model (BiRefNet or RMBG-2.0).
  3. View and download the processed image with the background removed.

Tab 2: URL Input

  1. Paste the URL of an image.
  2. Select a model (BiRefNet or RMBG-2.0).
  3. View and download the processed image with the background removed.

Tab 3: File Output

  1. Upload an image file.
  2. Select a model (BiRefNet or RMBG-2.0).
  3. Get the path to the processed PNG file with transparency.

Example

  • Use the provided example image (ironman.jpg) to test the tool.

How It Works

  1. Model Loading:
    • Loads pre-trained segmentation models from Hugging Face.
  2. Image Preprocessing:
    • Resizes and normalizes the input image.
  3. Background Removal:
    • The model generates a mask for the image background.
    • The mask is applied to create a transparent background.
  4. Output:
    • Processed image is displayed or saved with an alpha channel.

Contributing

Feel free to submit issues or pull requests for improvements or bug fixes.