File size: 856 Bytes
66afc13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fbd1311
 
ff00cbb
1c46a0a
fbd1311
 
66afc13
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import gradio as gr
from rembg import remove
from PIL import Image
import io

def remove_background(input_image):
    # Convert the image to bytes
    img_byte_arr = io.BytesIO()
    input_image.save(img_byte_arr, format="PNG")
    img_byte_arr = img_byte_arr.getvalue()

    # Apply background removal using rembg
    output_bytes = remove(img_byte_arr)

    # Convert the output (bytes) back into a PIL image
    output_image = Image.open(io.BytesIO(output_bytes))
    return output_image

# Create the Gradio interface
demo = gr.Interface(
    fn=remove_background,
    inputs=gr.Image(type="pil", label="Upload an image or Use Camera",sources="upload"),
    outputs=gr.Image(label="Processed Image",show_share_button=False, show_fullscreen_button=False),
    css="footer {visibility: hidden}"  # Hide the footer
)

# Launch the Gradio app
demo.launch()