File size: 1,377 Bytes
de2aa9b
ba4d1a9
 
de2aa9b
ba4d1a9
 
 
 
 
 
 
 
 
 
 
 
 
de2aa9b
ba4d1a9
 
 
 
 
 
 
 
 
 
 
 
 
 
de2aa9b
ba4d1a9
de2aa9b
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
import gradio as gr
import cv2
import numpy as np

from PIL import Image
from transparent_background import Remover

# Load model
remover = Remover() # default setting
remover = Remover(mode='fast', jit=True, device='cuda:0', ckpt='~/latest.pth') # custom setting
remover = Remover(mode='base-nightly') # nightly release checkpoint

# Usage for image



def doo(image):
    return "Hello " + name + "!!"
    img = Image.fromarray(image).convert('RGB') # read image
    out = remover.process(img) # default setting - transparent background
    out = remover.process(img, type='rgba') # same as above
    out = remover.process(img, type='map') # object map only
    out = remover.process(img, type='green') # image matting - green screen
    out = remover.process(img, type='white') # change backround with white color
    out = remover.process(img, type=[255, 0, 0]) # change background with color code [255, 0, 0]
    out = remover.process(img, type='blur') # blur background
    out = remover.process(img, type='overlay') # overlay object map onto the image
    out = remover.process(img, type='samples/background.jpg') # use another image as a background
    
    out = remover.process(img, threshold=0.5) # use threhold parameter for hard prediction.
    
    out.save('output.png') # save result

iface = gr.Interface(fn=doo, inputs="image", outputs="image")
iface.launch()