File size: 3,997 Bytes
3d35e10
 
8683813
3d35e10
a0d5e9e
8683813
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2c8d5da
8683813
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import gradio as gr

from annotator.util import resize_image, HWC3

DESCRIPTION = '# ControlNet v1.1 (cpu_only)'

model_canny = None


def canny(img, res, l, h):
    img = resize_image(HWC3(img), res)
    global model_canny
    if model_canny is None:
        from annotator.canny import CannyDetector
        model_canny = CannyDetector()
    result = model_canny(img, l, h)
    return [result]

model_openpose = None


def openpose(img, res, hand_and_face):
    img = resize_image(HWC3(img), res)
    global model_openpose
    if model_openpose is None:
        from annotator.openpose import OpenposeDetector
        model_openpose = OpenposeDetector()
    result = model_openpose(img, hand_and_face)
    return [result]


model_content_shuffler = None


def content_shuffler(img, res):
    img = resize_image(HWC3(img), res)
    global model_content_shuffler
    if model_content_shuffler is None:
        from annotator.shuffle import ContentShuffleDetector
        model_content_shuffler = ContentShuffleDetector()
    result = model_content_shuffler(img)
    return [result]


model_color_shuffler = None


def color_shuffler(img, res):
    img = resize_image(HWC3(img), res)
    global model_color_shuffler
    if model_color_shuffler is None:
        from annotator.shuffle import ColorShuffleDetector
        model_color_shuffler = ColorShuffleDetector()
    result = model_color_shuffler(img)
    return [result]


block = gr.Blocks().queue()
with block:
    gr.Markdown(DESCRIPTION)
    with gr.Row():
        gr.Markdown("## Canny Edge")
    with gr.Row():
        with gr.Column():
            input_image = gr.Image(source='upload', type="numpy")
            low_threshold = gr.Slider(label="low_threshold", minimum=1, maximum=255, value=100, step=1)
            high_threshold = gr.Slider(label="high_threshold", minimum=1, maximum=255, value=200, step=1)
            resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
            run_button = gr.Button(label="Run")
        with gr.Column():
            gallery = gr.Gallery(label="Generated images", show_label=False).style(height="auto")
    run_button.click(fn=canny, inputs=[input_image, resolution, low_threshold, high_threshold], outputs=[gallery])

    with gr.Row():
        gr.Markdown("## Openpose")
    with gr.Row():
        with gr.Column():
            input_image = gr.Image(source='upload', type="numpy")
            hand_and_face = gr.Checkbox(label='Hand and Face', value=False)
            resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
            run_button = gr.Button(label="Run")
        with gr.Column():
            gallery = gr.Gallery(label="Generated images", show_label=False).style(height="auto")
    run_button.click(fn=openpose, inputs=[input_image, resolution, hand_and_face], outputs=[gallery])

    with gr.Row():
        gr.Markdown("## Content Shuffle")
    with gr.Row():
        with gr.Column():
            input_image = gr.Image(source='upload', type="numpy")
            resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
            run_button = gr.Button(label="Run")
        with gr.Column():
            gallery = gr.Gallery(label="Generated images", show_label=False).style(height="auto")
    run_button.click(fn=content_shuffler, inputs=[input_image, resolution], outputs=[gallery])

    with gr.Row():
        gr.Markdown("## Color Shuffle")
    with gr.Row():
        with gr.Column():
            input_image = gr.Image(source='upload', type="numpy")
            resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
            run_button = gr.Button(label="Run")
        with gr.Column():
            gallery = gr.Gallery(label="Generated images", show_label=False).style(height="auto")
    run_button.click(fn=color_shuffler, inputs=[input_image, resolution], outputs=[gallery])


block.launch(server_name='0.0.0.0')