CoolFace
Apppublic

SIGGRAPH2022/DCT-Net

sourceHugging Faceupdated 4y agoView on Hugging Face
14likes
app.py34 linesDownload Raw Back to root
1import os 2os.system('pip install "modelscope[cv]" -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html')3import gradio as gr4import numpy as np5from modelscope.outputs import OutputKeys6from modelscope.pipelines import pipeline7from modelscope.utils.constant import Tasks8from modelscope.hub.snapshot_download import snapshot_download9 10model_dir = snapshot_download('damo/cv_unet_person-image-cartoon_compound-models', cache_dir='.')11 12img_cartoon = pipeline(13    Tasks.image_portrait_stylization,14    model='damo/cv_unet_person-image-cartoon_compound-models')15 16 17def infer(image):18    result = img_cartoon(image.name)19    out = result[OutputKeys.OUTPUT_IMG]20    out = np.clip(out, 0, 255).astype(np.uint8)21    return out[:, :, ::-1]22 23 24with gr.Blocks() as demo:25    title= gr.Markdown("""26    # Gradio Demo for [DCT-Net: Domain-Calibrated Translation for Portrait Stylization](https://github.com/menyifang/DCT-Net), SIGGRAPH 2022 (TOG); Multi-style cartoonization27    """28    )29    with gr.Row():30        image = gr.Image(label='Input', type='file')31        result = gr.Image(label='Output')32    run_button = gr.Button('Run')33    run_button.click(fn=infer, inputs=image, outputs=result)34demo.launch()