fix issue with file path parameter
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
|
|
2 |
from rembg import remove
|
3 |
from PIL import Image
|
4 |
import logging
|
|
|
5 |
|
6 |
# Set up logging
|
7 |
logging.basicConfig(level=logging.INFO)
|
@@ -17,7 +18,12 @@ def remove_background(input_image):
|
|
17 |
output_image = output_image.convert('RGB')
|
18 |
logging.info("Converted to RGB mode")
|
19 |
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
except Exception as e:
|
23 |
logging.error(f"An error occurred: {e}")
|
@@ -27,17 +33,11 @@ def remove_background(input_image):
|
|
27 |
iface = gr.Interface(
|
28 |
fn=remove_background,
|
29 |
inputs=gr.Image(type="pil"),
|
30 |
-
outputs=gr.
|
31 |
title="Background Remover",
|
32 |
description="Upload an image to remove the background and download the result.",
|
33 |
allow_flagging="never",
|
34 |
-
examples=None,
|
35 |
)
|
36 |
|
37 |
-
|
38 |
-
iface.launch(
|
39 |
-
inbrowser=True,
|
40 |
-
share=True,
|
41 |
-
file_path="output_image.png", # Default output file name
|
42 |
-
live=True,
|
43 |
-
)
|
|
|
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)
|
|
|
18 |
output_image = output_image.convert('RGB')
|
19 |
logging.info("Converted to RGB mode")
|
20 |
|
21 |
+
# Save the output image to a temporary file
|
22 |
+
output_path = "output_image.png"
|
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}")
|
|
|
33 |
iface = gr.Interface(
|
34 |
fn=remove_background,
|
35 |
inputs=gr.Image(type="pil"),
|
36 |
+
outputs=gr.File(label="Download the output image"),
|
37 |
title="Background Remover",
|
38 |
description="Upload an image to remove the background and download the result.",
|
39 |
allow_flagging="never",
|
|
|
40 |
)
|
41 |
|
42 |
+
if __name__ == "__main__":
|
43 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|