CoolFace
Apppublic

hysts/ControlNet

sourceHugging Facemitupdated 3y agoView on Hugging Face
993likes
app_normal.py94 linesDownload Raw Back to root
1# This file is adapted from https://github.com/lllyasviel/ControlNet/blob/f4748e3630d8141d7765e2bd9b1e348f47847707/gradio_normal2image.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 Normal 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_normal_image = gr.Checkbox(label='Is normal 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='Normal Resolution',29                                                  minimum=128,30                                                  maximum=512,31                                                  value=384,32                                                  step=1)33                    bg_threshold = gr.Slider(34                        label='Normal background threshold',35                        minimum=0.0,36                        maximum=1.0,37                        value=0.4,38                        step=0.01)39                    num_steps = gr.Slider(label='Steps',40                                          minimum=1,41                                          maximum=100,42                                          value=20,43                                          step=1)44                    guidance_scale = gr.Slider(label='Guidance Scale',45                                               minimum=0.1,46                                               maximum=30.0,47                                               value=9.0,48                                               step=0.1)49                    seed = gr.Slider(label='Seed',50                                     minimum=-1,51                                     maximum=2147483647,52                                     step=1,53                                     randomize=True)54                    a_prompt = gr.Textbox(55                        label='Added Prompt',56                        value='best quality, extremely detailed')57                    n_prompt = gr.Textbox(58                        label='Negative Prompt',59                        value=60                        'longbody, lowres, bad anatomy, bad hands, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality'61                    )62            with gr.Column():63                result = gr.Gallery(label='Output',64                                    show_label=False,65                                    elem_id='gallery').style(grid=2,66                                                             height='auto')67        inputs = [68            input_image,69            prompt,70            a_prompt,71            n_prompt,72            num_samples,73            image_resolution,74            detect_resolution,75            num_steps,76            guidance_scale,77            seed,78            bg_threshold,79            is_normal_image,80        ]81        prompt.submit(fn=process, inputs=inputs, outputs=result)82        run_button.click(fn=process,83                         inputs=inputs,84                         outputs=result,85                         api_name='normal')86    return demo87 88 89if __name__ == '__main__':90    from model import Model91    model = Model()92    demo = create_demo(model.process_normal)93    demo.queue().launch()94