File size: 881 Bytes
f5bf298
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import numpy as np
from modelscope.outputs import OutputKeys
from modelscope.pipelines import pipeline
from modelscope.utils.constant import Tasks
from modelscope.hub.snapshot_download import snapshot_download

model_dir = snapshot_download('damo/cv_unet_person-image-cartoon_compound-models', cache_dir='.')

img_cartoon = pipeline(
    Tasks.image_portrait_stylization,
    model='damo/cv_unet_person-image-cartoon_compound-models')


def infer(image):
    result = img_cartoon(image.name)
    out = result[OutputKeys.OUTPUT_IMG]
    out = np.clip(out, 0, 255).astype(np.uint8)
    return out[:, :, ::-1]


with gr.Blocks() as demo:
    with gr.Row():
        image = gr.Image(label='Input', type='file')
        run_button = gr.Button('Run')
        result = gr.Image(label='Output')
    run_button.click(fn=infer, inputs=image, outputs=result)
demo.launch()