Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,3 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
import gradio as gr
|
6 |
from rembg import remove
|
7 |
from PIL import Image
|
@@ -12,13 +8,16 @@ def remove_background(input_image):
|
|
12 |
output = remove(input) # remove background
|
13 |
return output
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
output_image = gr.inputs.Image(type="filepath", label="Output Image")
|
19 |
-
|
20 |
|
|
|
|
|
|
|
21 |
|
|
|
|
|
22 |
|
23 |
# create the interface
|
24 |
iface = gr.Interface(
|
@@ -26,9 +25,12 @@ iface = gr.Interface(
|
|
26 |
inputs=input_image,
|
27 |
outputs=output_image,
|
28 |
title='Image Background Remover',
|
29 |
-
description='Upload an image and it will remove.'
|
|
|
30 |
)
|
31 |
|
32 |
-
#
|
33 |
-
|
34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
from rembg import remove
|
3 |
from PIL import Image
|
|
|
8 |
output = remove(input) # remove background
|
9 |
return output
|
10 |
|
11 |
+
def download_image(output_image):
|
12 |
+
img_bytes = output_image.getvalue()
|
13 |
+
return gradio.Interface.download(img_bytes, "output_image.png")
|
|
|
|
|
14 |
|
15 |
+
# define input and output interfaces
|
16 |
+
input_image = gr.inputs.Image(type="file", label="Input Image")
|
17 |
+
output_image = gr.outputs.Image(type="file", label="Output Image")
|
18 |
|
19 |
+
# define the download button
|
20 |
+
download_button = gr.InterfaceFn(download_image, output_image, title="Download")
|
21 |
|
22 |
# create the interface
|
23 |
iface = gr.Interface(
|
|
|
25 |
inputs=input_image,
|
26 |
outputs=output_image,
|
27 |
title='Image Background Remover',
|
28 |
+
description='Upload an image and it will remove.',
|
29 |
+
allow_download=True
|
30 |
)
|
31 |
|
32 |
+
# combine the main interface and the download button
|
33 |
+
interface_with_download = gr.Interface([iface, download_button], "grid")
|
34 |
|
35 |
+
# launch the interface
|
36 |
+
interface_with_download.launch()
|