CoolFace
Apppublic

HIST/ControlNet

sourceHugging Faceupdated 4y agoView on Hugging Face
0likes
app.py78 linesDownload Raw Back to root
1#!/usr/bin/env python2 3from __future__ import annotations4 5import os6import shlex7import subprocess8 9import gradio as gr10 11if os.getenv('SYSTEM') == 'spaces':12    with open('patch') as f:13        subprocess.run(shlex.split('patch -p1'), stdin=f, cwd='ControlNet')14    commands = [15        'wget https://huggingface.co/ckpt/ControlNet/resolve/main/dpt_hybrid-midas-501f0c75.pt -O dpt_hybrid-midas-501f0c75.pt',16        'wget https://huggingface.co/ckpt/ControlNet/resolve/main/body_pose_model.pth -O body_pose_model.pth',17        'wget https://huggingface.co/ckpt/ControlNet/resolve/main/hand_pose_model.pth -O hand_pose_model.pth',18        'wget https://huggingface.co/ckpt/ControlNet/resolve/main/mlsd_large_512_fp32.pth -O mlsd_large_512_fp32.pth',19        'wget https://huggingface.co/ckpt/ControlNet/resolve/main/mlsd_tiny_512_fp32.pth -O mlsd_tiny_512_fp32.pth',20        'wget https://huggingface.co/ckpt/ControlNet/resolve/main/network-bsds500.pth -O network-bsds500.pth',21        'wget https://huggingface.co/ckpt/ControlNet/resolve/main/upernet_global_small.pth -O upernet_global_small.pth',22    ]23    for command in commands:24        subprocess.run(shlex.split(command), cwd='ControlNet/annotator/ckpts/')25 26from gradio_canny2image import create_demo as create_demo_canny27from gradio_depth2image import create_demo as create_demo_depth28from gradio_fake_scribble2image import create_demo as create_demo_fake_scribble29from gradio_hed2image import create_demo as create_demo_hed30from gradio_hough2image import create_demo as create_demo_hough31from gradio_normal2image import create_demo as create_demo_normal32from gradio_pose2image import create_demo as create_demo_pose33from gradio_scribble2image import create_demo as create_demo_scribble34from gradio_scribble2image_interactive import \35    create_demo as create_demo_scribble_interactive36from gradio_seg2image import create_demo as create_demo_seg37from model import Model38 39DESCRIPTION = '''# ControlNet40 41This is an unofficial demo for [https://github.com/lllyasviel/ControlNet](https://github.com/lllyasviel/ControlNet).42'''43if (SPACE_ID := os.getenv('SPACE_ID')) is not None:44    DESCRIPTION += f'''<p>For faster inference without waiting in queue, you may duplicate the space and upgrade to GPU in settings.<br/>45<a href="https://huggingface.co/spaces/{SPACE_ID}?duplicate=true">46<img style="margin-top: 0em; margin-bottom: 0em" src="https://bit.ly/3gLdBN6" alt="Duplicate Space"></a>47<p/>48'''49 50model = Model()51 52with gr.Blocks(css='style.css') as demo:53    gr.Markdown(DESCRIPTION)54    with gr.Tabs():55        with gr.TabItem('Canny'):56            create_demo_canny(model.process_canny)57        with gr.TabItem('Hough'):58            create_demo_hough(model.process_hough)59        with gr.TabItem('HED'):60            create_demo_hed(model.process_hed)61        with gr.TabItem('Scribble'):62            create_demo_scribble(model.process_scribble)63        with gr.TabItem('Scribble Interactive'):64            create_demo_scribble_interactive(65                model.process_scribble_interactive)66        with gr.TabItem('Fake Scribble'):67            create_demo_fake_scribble(model.process_fake_scribble)68        with gr.TabItem('Pose'):69            create_demo_pose(model.process_pose)70        with gr.TabItem('Segmentation'):71            create_demo_seg(model.process_seg)72        with gr.TabItem('Depth'):73            create_demo_depth(model.process_depth)74        with gr.TabItem('Normal map'):75            create_demo_normal(model.process_normal)76 77demo.queue(api_open=False).launch()78