File size: 529 Bytes
f28c437
 
 
f1ce139
f28c437
 
f1ce139
f28c437
 
 
 
 
 
 
f1ce139
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import paddlehub as hub
import gradio as gr


module = hub.Module(name="lseg")


def segment(image, labels):
    results = module.segment(
        image=image[..., ::-1],
        labels=labels.split('\n')
    )
    return [results['color'][..., ::-1], results['mix'][..., ::-1], *[v[..., ::-1] for v in results['classes'].values()]]


gr.Interface(
    fn=segment,
    inputs=['image', gr.Textbox(
        placeholder='other\ncat', lines=5, max_lines=50)],
    outputs=[gr.Gallery().style(grid=[2, 3], height="auto")]
).launch()