File size: 1,690 Bytes
1e4d453
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8105001
1e4d453
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import cv2
import numpy as np
import gradio as gr
import paddlehub as hub
from methods.img2pixl import pixL
from methods.combine import combine
from methods.white_box_cartoonizer.cartoonize import WB_Cartoonize
model = hub.Module(name='U2Net')
pixl = pixL()
combine = combine()

def func_tab1(image,pixel_size, checkbox1):
  image = cv2.imread(image.name)
  image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
  image = WB_Cartoonize().infer(image)
  image = np.array(image)
  image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
  if checkbox1:
    result = model.Segmentation(
        images=[image],
        paths=None,
        batch_size=1,
        input_size=320,  
        output_dir='output',
        visualization=True)
    result = combine.combiner(images = pixl.toThePixL([result[0]['front'][:,:,::-1], result[0]['mask']], 
                                                      pixel_size),
                              background_image = image)
  else:
    result = pixl.toThePixL([image], pixel_size)
  return result

def func_tab2():
  pass

inputs_tab1 = [gr.inputs.Image(type='file', label="Image"),
               gr.Slider(4, 100, value=12, step = 2, label="Pixel Size"),
               gr.Checkbox(label="Object-Oriented Inference", value=False)]
outputs_tab1 = [gr.Image(type="numpy",label="Front")]

inputs_tab2 = [gr.Video()]
outputs_tab2 = [gr.Video()]

tab1 = gr.Interface(fn = func_tab1,
                    inputs = inputs_tab1,
                    outputs = outputs_tab1)
#Pixera for Videos
tab2 = gr.Interface(fn = func_tab2,
                    inputs = inputs_tab2,
                    outputs = outputs_tab2)

gr.TabbedInterface([tab1], ["Pixera for Images"]).launch()