Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
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 |
-
#
|
20 |
-
|
21 |
-
output.save(
|
22 |
-
|
23 |
-
output = Image.open(output_bytes)
|
24 |
|
25 |
-
return
|
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="
|
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="""
|