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')