Spaces:
addsw11
/
Running on Zero

File size: 1,716 Bytes
c4b3a12
2c9a089
 
1138828
 
2c9a089
 
 
1138828
 
 
 
 
 
 
2c9a089
 
 
 
1567106
 
321c2b4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a21e85d
 
 
 
 
 
 
 
 
2c9a089
 
a21e85d
 
 
 
 
 
 
 
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import spaces
import gradio as gr
from transparent_background import Remover
from PIL import Image
import numpy as np

def remove_background(image):
    remover = Remover()
    if isinstance(image, Image.Image):
        output = remover.process(image)
    elif isinstance(image, np.ndarray):
        image_pil = Image.fromarray(image)
        output = remover.process(image_pil)
    else:
        raise TypeError("Unsupported image type")
    return output

iface = gr.Interface(
    fn=remove_background,
    inputs=gr.Image(label="Upload Image"),
    outputs=gr.Image(label="Output Image"),
    live=True,
    css="""
        .gradio-container {
            background-color: #f0f0f0;
            font-family: Arial, sans-serif;
        }
        .gr-inputs, .gr-outputs {
            display: flex;
            flex-direction: column;
            align-items: center;
        }
        .gr-button {
            margin-top: 20px;
            background-color: #4CAF50;
            color: white;
            border: none;
            padding: 10px 20px;
            text-align: center;
            font-size: 16px;
            border-radius: 5px;
            transition: background-color 0.3s;
        }
        .gr-button:hover {
            background-color: #45a049;
        }
        .gr-button-container {
            display: flex;
            justify-content: space-between;
            width: 100%;
            max-width: 300px;
            margin-top: 20px;
        }
    """,
    layout="vertical",
)

iface.launch(
    inputs=[gr.Image(label="Upload Image")],
    outputs=[gr.Image(label="Output Image")],
    layout="vertical",
    live=False,
    show_submit_button=True,
    show_clear_button=True,
)