File size: 465 Bytes
f28c437
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
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=['gallery']).launch()