innoai commited on
Commit
ffc7966
·
verified ·
1 Parent(s): 1138828

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -3
app.py CHANGED
@@ -3,6 +3,7 @@ import gradio as gr
3
  from transparent_background import Remover
4
  from PIL import Image
5
  import numpy as np
 
6
 
7
  @spaces.GPU
8
  def remove_background(image):
@@ -14,14 +15,35 @@ def remove_background(image):
14
  output = remover.process(image_pil)
15
  else:
16
  raise TypeError("Unsupported image type")
 
 
 
 
 
 
 
17
  return output
18
 
 
19
  iface = gr.Interface(
20
  fn=remove_background,
21
  inputs=gr.Image(label="Upload Image"),
22
- outputs=gr.Image(label="Output Image"),
23
- title="Background Remover",
24
- description="Upload an image and get the background removed."
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  )
26
 
27
  if __name__ == "__main__":
 
3
  from transparent_background import Remover
4
  from PIL import Image
5
  import numpy as np
6
+ import io
7
 
8
  @spaces.GPU
9
  def remove_background(image):
 
15
  output = remover.process(image_pil)
16
  else:
17
  raise TypeError("Unsupported image type")
18
+
19
+ # Ensure the output image has a transparent background and is saved in PNG format
20
+ with io.BytesIO() as output_bytes:
21
+ output.save(output_bytes, format="PNG")
22
+ output_bytes.seek(0)
23
+ output = Image.open(output_bytes)
24
+
25
  return output
26
 
27
+ # Interface setup
28
  iface = gr.Interface(
29
  fn=remove_background,
30
  inputs=gr.Image(label="Upload Image"),
31
+ outputs=gr.Image(label="Output Image", type="pil"),
32
+ title="AI Background Remover - Automatically Remove Image Backgrounds",
33
+ description="Upload an image and our AI-powered background remover will automatically make the background transparent. Perfect for various needs requiring transparent images.",
34
+ article="""
35
+ ## How to Use
36
+ 1. Click **Upload Image** or drag and drop an image into the upload area.
37
+ 2. Click the **Submit** button and wait for a moment. The processed image will appear in the output area on the right.
38
+ 3. The background of the processed image will be transparent, and the image will be in PNG format for easy use.
39
+
40
+ ### Application Scenarios
41
+ - **E-commerce**: Remove backgrounds from product images to create clean product photos.
42
+ - **Graphic Design**: Quickly get images with transparent backgrounds for composition and design.
43
+ - **Social Media**: Create avatars or icons with transparent backgrounds that blend perfectly on various backgrounds.
44
+
45
+ Our tool leverages the latest AI technology to efficiently and accurately remove image backgrounds, saving you time and effort.
46
+ """
47
  )
48
 
49
  if __name__ == "__main__":