Spaces:
Running
Running
import spaces | |
import gradio as gr | |
from transparent_background import Remover | |
from PIL import Image | |
import numpy as np | |
import io | |
def remove_background(image): | |
remover = Remover() | |
if isinstance(image, Image.Image): | |
output = remover.process(image) | |
elif isinstance(image, np.ndarray): | |
image_pil = Image.fromarray(image) | |
output = remover.process(image_pil) | |
else: | |
raise TypeError("Unsupported image type") | |
# Ensure the output image has a transparent background and is saved in PNG format | |
with io.BytesIO() as output_bytes: | |
output.save(output_bytes, format="PNG") | |
output_bytes.seek(0) | |
output = Image.open(output_bytes) | |
return output | |
# Interface setup | |
iface = gr.Interface( | |
fn=remove_background, | |
inputs=gr.Image(label="Upload Image"), | |
outputs=gr.Image(label="Output Image", type="pil"), | |
title="AI Background Remover - Automatically Remove Image Backgrounds", | |
description="Upload an image and our AI-powered background remover will automatically make the background transparent. Perfect for various needs requiring transparent images.", | |
article=""" | |
## How to Use | |
1. Click **Upload Image** or drag and drop an image into the upload area. | |
2. Click the **Submit** button and wait for a moment. The processed image will appear in the output area on the right. | |
3. The background of the processed image will be transparent, and the image will be in PNG format for easy use. | |
### Application Scenarios | |
- **E-commerce**: Remove backgrounds from product images to create clean product photos. | |
- **Graphic Design**: Quickly get images with transparent backgrounds for composition and design. | |
- **Social Media**: Create avatars or icons with transparent backgrounds that blend perfectly on various backgrounds. | |
Our tool leverages the latest AI technology to efficiently and accurately remove image backgrounds, saving you time and effort. | |
""" | |
) | |
if __name__ == "__main__": | |
iface.launch() | |