hysts/ControlNet
993
1# This file is adapted from https://github.com/lllyasviel/ControlNet/blob/f4748e3630d8141d7765e2bd9b1e348f47847707/gradio_depth2image.py2# The original license file is LICENSE.ControlNet in this repo.3import gradio as gr4 5 6def create_demo(process, max_images=12, default_num_images=3):7 with gr.Blocks() as demo:8 with gr.Row():9 gr.Markdown('## Control Stable Diffusion with Depth Maps')10 with gr.Row():11 with gr.Column():12 input_image = gr.Image(source='upload', type='numpy')13 prompt = gr.Textbox(label='Prompt')14 run_button = gr.Button(label='Run')15 with gr.Accordion('Advanced options', open=False):16 is_depth_image = gr.Checkbox(label='Is depth image',17 value=False)18 num_samples = gr.Slider(label='Images',19 minimum=1,20 maximum=max_images,21 value=default_num_images,22 step=1)23 image_resolution = gr.Slider(label='Image Resolution',24 minimum=256,25 maximum=512,26 value=512,27 step=256)28 detect_resolution = gr.Slider(label='Depth Resolution',29 minimum=128,30 maximum=512,31 value=384,32 step=1)33 num_steps = gr.Slider(label='Steps',34 minimum=1,35 maximum=100,36 value=20,37 step=1)38 guidance_scale = gr.Slider(label='Guidance Scale',39 minimum=0.1,40 maximum=30.0,41 value=9.0,42 step=0.1)43 seed = gr.Slider(label='Seed',44 minimum=-1,45 maximum=2147483647,46 step=1,47 randomize=True)48 a_prompt = gr.Textbox(49 label='Added Prompt',50 value='best quality, extremely detailed')51 n_prompt = gr.Textbox(52 label='Negative Prompt',53 value=54 'longbody, lowres, bad anatomy, bad hands, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality'55 )56 with gr.Column():57 result = gr.Gallery(label='Output',58 show_label=False,59 elem_id='gallery').style(grid=2,60 height='auto')61 inputs = [62 input_image,63 prompt,64 a_prompt,65 n_prompt,66 num_samples,67 image_resolution,68 detect_resolution,69 num_steps,70 guidance_scale,71 seed,72 is_depth_image,73 ]74 prompt.submit(fn=process, inputs=inputs, outputs=result)75 run_button.click(fn=process,76 inputs=inputs,77 outputs=result,78 api_name='depth')79 return demo80 81 82if __name__ == '__main__':83 from model import Model84 model = Model()85 demo = create_demo(model.process_depth)86 demo.queue().launch()87 