innoai commited on
Commit
1949160
1 Parent(s): e8176ca

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -4,6 +4,7 @@ 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):
@@ -16,19 +17,18 @@ def remove_background(image):
16
  else:
17
  raise TypeError("Unsupported image type")
18
 
19
- # 确保输出图片的背景是透明的,并以PNG格式保存
20
- output_bytes = io.BytesIO()
21
- output.save(output_bytes, format="PNG")
22
- output_bytes.seek(0)
23
- output = Image.open(output_bytes)
24
 
25
- return output
26
 
27
  # 界面设置
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="""
 
4
  from PIL import Image
5
  import numpy as np
6
  import io
7
+ import tempfile
8
 
9
  @spaces.GPU
10
  def remove_background(image):
 
17
  else:
18
  raise TypeError("Unsupported image type")
19
 
20
+ # 保存PNG图片到临时文件
21
+ temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".png")
22
+ output.save(temp_file, format="PNG")
23
+ temp_file.close()
 
24
 
25
+ return temp_file.name
26
 
27
  # 界面设置
28
  iface = gr.Interface(
29
  fn=remove_background,
30
  inputs=gr.Image(label="Upload Image"),
31
+ outputs=gr.Image(label="Output Image", type="filepath"),
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="""