show output image after removing the background
Browse files
app.py
CHANGED
@@ -2,7 +2,6 @@ import gradio as gr
|
|
2 |
from rembg import remove
|
3 |
from PIL import Image
|
4 |
import logging
|
5 |
-
import os
|
6 |
|
7 |
# Set up logging
|
8 |
logging.basicConfig(level=logging.INFO)
|
@@ -23,19 +22,22 @@ def remove_background(input_image):
|
|
23 |
output_image.save(output_path)
|
24 |
logging.info(f"Saved output image {output_path}")
|
25 |
|
26 |
-
return output_path
|
27 |
|
28 |
except Exception as e:
|
29 |
logging.error(f"An error occurred: {e}")
|
30 |
-
return None
|
31 |
|
32 |
# Gradio interface
|
33 |
iface = gr.Interface(
|
34 |
fn=remove_background,
|
35 |
inputs=gr.Image(type="pil"),
|
36 |
-
outputs=
|
|
|
|
|
|
|
37 |
title="Background Remover",
|
38 |
-
description="Upload an image to remove the background
|
39 |
allow_flagging="never",
|
40 |
)
|
41 |
|
|
|
2 |
from rembg import remove
|
3 |
from PIL import Image
|
4 |
import logging
|
|
|
5 |
|
6 |
# Set up logging
|
7 |
logging.basicConfig(level=logging.INFO)
|
|
|
22 |
output_image.save(output_path)
|
23 |
logging.info(f"Saved output image {output_path}")
|
24 |
|
25 |
+
return output_image, output_path
|
26 |
|
27 |
except Exception as e:
|
28 |
logging.error(f"An error occurred: {e}")
|
29 |
+
return None, None
|
30 |
|
31 |
# Gradio interface
|
32 |
iface = gr.Interface(
|
33 |
fn=remove_background,
|
34 |
inputs=gr.Image(type="pil"),
|
35 |
+
outputs=[
|
36 |
+
gr.Image(type="pil", label="Output Image"),
|
37 |
+
gr.File(label="Download the output image")
|
38 |
+
],
|
39 |
title="Background Remover",
|
40 |
+
description="Upload an image to remove the background. You can view the result and download it.",
|
41 |
allow_flagging="never",
|
42 |
)
|
43 |
|