File size: 1,140 Bytes
a135247
 
 
f036466
a135247
 
 
 
 
 
a1071aa
 
 
f036466
a1071aa
caab2d1
 
45176ec
a1071aa
a5ffb52
 
 
3b06529
a5ffb52
 
f036466
 
 
 
 
 
 
a1071aa
 
f036466
 
a1071aa
 
13ba839
a1071aa
 
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
41
42
import gradio as gr
from rembg import remove
from PIL import Image
from io import BytesIO

def remove_background(input_image):
    input = Image.open(input_image) # load image
    output = remove(input) # remove background
    return output

def download_image(output_image):
    img_bytes = output_image.getvalue()
    return gradio.Interface.download(img_bytes, "output_image.png")

# define input and output interfaces
input_image = gr.inputs.Image(type="filepath", label="Input Image")
output_image = gr.inputs.Image(type="filepath", label="Output Image")

# define the download button
download_button = gr.Interface(
    fn=download_image,
    inputs=output_image,
    outputs="file",
    title="Download"
)

# create the interface
iface = gr.Interface(
    fn=remove_background, 
    inputs=input_image, 
    outputs=output_image,
    title='Image Background Remover',
    description='Upload an image and it will remove.',
    allow_download=True
)

# combine the main interface and the download button
interface_with_download = gr.Interface([iface, download_button], "grid")

# launch the interface
interface_with_download.launch()