Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,31 @@
|
|
1 |
import gradio as gr
|
2 |
from rembg import remove
|
3 |
from PIL import Image
|
|
|
4 |
|
5 |
def remove_background(input_image):
|
6 |
-
|
7 |
input = Image.open(input_image) # load image
|
8 |
output = remove(input) # remove background
|
9 |
return output
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
-
|
13 |
-
output_image =
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
description='Upload an image and it will remove.')
|
20 |
|
21 |
-
|
|
|
22 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from rembg import remove
|
3 |
from PIL import Image
|
4 |
+
import io
|
5 |
|
6 |
def remove_background(input_image):
|
|
|
7 |
input = Image.open(input_image) # load image
|
8 |
output = remove(input) # remove background
|
9 |
return output
|
10 |
|
11 |
+
def download_output(output_image):
|
12 |
+
output_bytes = io.BytesIO()
|
13 |
+
output_image.save(output_bytes, format="PNG")
|
14 |
+
output_bytes.seek(0)
|
15 |
+
return output_bytes
|
16 |
+
|
17 |
+
input_image = gr.inputs.Image(type="file", label="Input Image")
|
18 |
+
output_image = gr.outputs.Image(type="pil", label="Output Image")
|
19 |
+
output_image_download = gr.outputs.Button(label="Download Output")
|
20 |
|
21 |
+
def background_removal_with_download(input_image):
|
22 |
+
output_image = remove_background(input_image)
|
23 |
+
output_image_download = gr.outputs.Button(label="Download Output")
|
24 |
+
download_button = gr.Interface(
|
25 |
+
download_output, inputs=gr.inputs.Image(type="pil", label="Output Image"), outputs="bytes",
|
26 |
+
interpretation="download", title="Download Output Image", live=False)
|
27 |
+
return output_image, download_button(output_image)
|
|
|
28 |
|
29 |
+
iface = gr.Interface(background_removal_with_download, inputs=input_image, outputs=[output_image, output_image_download],
|
30 |
+
title='Image Background Remover', description='Upload an image and it will remove.')
|
31 |
iface.launch()
|