rdjarbeng commited on
Commit
d73301b
·
1 Parent(s): 9e5b486

add app and requirements

Browse files
Files changed (2) hide show
  1. app.py +43 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 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)
8
+
9
+ def remove_background(input_image):
10
+ try:
11
+ # Remove the background
12
+ output_image = remove(input_image)
13
+ logging.info("Background removed")
14
+
15
+ # Convert to RGB mode if necessary
16
+ if output_image.mode != 'RGB':
17
+ output_image = output_image.convert('RGB')
18
+ logging.info("Converted to RGB mode")
19
+
20
+ return output_image
21
+
22
+ except Exception as e:
23
+ logging.error(f"An error occurred: {e}")
24
+ return None
25
+
26
+ # Gradio interface
27
+ iface = gr.Interface(
28
+ fn=remove_background,
29
+ inputs=gr.Image(type="pil"),
30
+ outputs=gr.Image(type="pil", label="Output Image"),
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
+ # Add a file output option for downloading the processed image
38
+ iface.launch(
39
+ inbrowser=True,
40
+ share=True,
41
+ file_path="output_image.png", # Default output file name
42
+ live=True,
43
+ )
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ rembg
2
+ pillow