File size: 931 Bytes
cfeffa8
f54197c
cfeffa8
f54197c
 
 
cfeffa8
f54197c
 
 
cfeffa8
f54197c
cfeffa8
f54197c
 
 
cfeffa8
f54197c
cfeffa8
f54197c
cfeffa8
f54197c
 
cfeffa8
f54197c
 
 
 
 
 
 
 
 
 
 
 
 
cfeffa8
 
f54197c
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
import numpy as np
from PIL import Image
import uuid
import os

def remove_bg(input_image):
    try: print(input_image.name)
    except: pass

    if not os.path.exists("./temp"): os.mkdir("./temp")

    output_path = f'./temp/Removed_{uuid.uuid4()}.png'
    
    input_array = np.array(input_image)

    output_array = remove(input_array)

    output_img = Image.fromarray(output_array)

    output_img.save(output_path)
    return output_path

with gr.Blocks() as app:
    with gr.Row():
        with gr.Column():
            input_image = gr.Image(label="Input Image")
            generate_btn = gr.Button(value="Remove Background")
        with gr.Column():
            output__image = gr.Image(label="Output Image")
    
    generate_btn.click(
        fn=remove_bg, 
        inputs=[input_image], 
        outputs=[output__image], 
        show_progress="full"
    )

app.launch()