File size: 1,191 Bytes
56a814d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
29
30
31
32
33
34
35
36
37
38
39
40
import gradio as gr
from rembg import remove
from PIL import Image
import io

def background_remover(input_image):
    input_bytes = input_image.read()  
    input_img = Image.open(io.BytesIO(input_bytes))
    output_img = remove(input_img) 
    
    buf = io.BytesIO()
    output_img.save(buf, format='PNG')
    buf.seek(0)
    return buf

description = """
This app uses the rembg library to remove the background from uploaded images.
Simply upload your image and let the model do its work. Download the result immediately after!
"""

with gr.Blocks() as demo:
    gr.Markdown("<h1 style='text-align: center;'>Background Remover</h1>")
    gr.Markdown(description)
    
    with gr.Row():
        with gr.Column(scale=1):
            input_image = gr.Image(type='file', label="Upload Image")
        with gr.Column(scale=1):
            output_image = gr.Image(type='pil', label="Result")

    with gr.Row():
         gr.Button("Remove Background").click(
             fn=background_remover,
             inputs=input_image,
             outputs=output_image
         )

    demo_examples = [["woman.jpg"], ["groot.jpg"]]
    demo.launch(share=True, examples=demo_examples, theme="soft")